ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
What is a function? Give some example?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is a function? Give some example?
Answer
# 1
In Sql Server Function are Like S.P Mean Batch of SQL 
command. But Function Must Return Single Value
In SQL Server Four Type Of Function
1)Table-Valued Function:Return Datatable
2)Scaler Valued Function:return Single value
3)Aggreated Funtion:Return Aggreatged Result set
4)System Funtion:used by system like Rowset etc.
 
Is This Answer Correct ?    6 Yes 5 No
Dinesh Sharma
 
  Re: What is a function? Give some example?
Answer
# 2
CREATE FUNCTION function_name
(@input_variables  type)
RETURNS data_type of result returned by function
AS
BEGIN
.....  SQL Statements
    RETURN (data_value)
END

Let's demonstrate this statement by writing a function.
Oracle has a useful function called NEXT_DAY that computes
the date of the next named day of the week (i.e., Sunday,
Monday, etc.) after the given date. Go ahead and write your
own function for SQL Server (see Listing 1 for the code to
create a scalar function using NEXT_DAY).

Inline Table-Valued Functions
Now create a function that returns a table. Use the
Northwind database; it contains customers, orders, and order
details. Suppose you want to analyze your customers by
ranking them from best to worst. The function that you write
will return the customerid, total sales, and rank of each
customer in a table that can then be used by itself or
joined within other tables. Furthermore, you will pass a
parameter to the function to filter the customers based on
the rank (e.g., top 3, top 10, etc.).

First, create a view in the Northwind database that
summarizes the total sales for each customer, as follows:


use Northwind
go
 if exists(select * from sysobjects where 
   name = 'vw_totalsales')
   drop view vw_totalsales
go
create view vw_totalsales
as
(select CustomerID,sum (UnitPrice * Quantity * 
   1 - Discount) as 'totalsales'
from Orders o 
inner join [Order Details] od
on (o.OrderID = od.OrderID)
group by Customerid )

To find the rank of each customer, you need to find the
number of distinct total sales values that are equal to or
less than the customer in question. See Listing 2 for the
code. Look more closely at the syntax you used. First of
all, in this function you stated "returns table." That tells
SQL Server that the function is returning a table of results
rather than a scalar value. But you didn't define the table
of results the function would be returning. Instead, you
followed it with a single return statement that has one huge
SELECT statement in it.
 
Is This Answer Correct ?    1 Yes 3 No
Ranjay
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What is lock escalation?  1
Which TCP/IP port does SQL Server run on?  2
What are the four main query statements?  3
could u plz explain about joins and views?  2
Please give me the SP for the below scenario. I have two tables named Table1 and Table2...I need to fetch record by record from Table1 and insert the record in to table2 where the value in the sno column of the table1 is even number. Value-Labs4
How to create logins using windows Authentication mode?  2
What is a Trace frag?Where can we use this?  1
The Difference between 'Count' and 'Count(*)'  12
table:employee EID ENAME MID(manager ids) 101 rama null 102 sita 101 103 siva 101 104 ganesh 103 . . . . . . for 103 ID the manager ID is 101(RAMA) and for 104 manager is SIVA if i give employee id (EID) you have to tell the manager for that EID write query? eample:if i give 102 .The query output should be manager for 102 ID that it should print RAMA as output  5
How to Display, Amount of Disk Activity Generated by Transact-SQL Statements?  1
What is the basic functions for master, msdb, tempdb databases? CSC2
What is the difference Between Sql-server 2000 & 2005 Value-Labs2
how can we use a composite key for two tables and how can we represent it BoA1
select empid empname from employee What is the result for the about query?  4
select top 5 * from emp order by newid() my question is , how this query get executed?  4
How to Check Whether a Global Temporary Exists in a SQL Database or not?  2
write query for fourth maximum salary from employee table Mind-Tree5
How do you check the performance of a query and how do you optimize it?  1
Explain different isolation levels?  3
how to rename the table  3
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com