Friday, January 21, 2011

Function returning more than one value in SQL Server

Function returning more than one value in SQL Server
Create
FUNCTION GetWarrantNotesDetails (@WarrantID varchar(22))
RETURNS @WarrantDetails Table
( Remarks varchar(1000)
, NoteDate datetime
, AddedBy varchar(36)
)
AS
BEGIN
INSERT INTO @WarrantDetails (Remarks, NoteDate, AddedBy)
SELECT TOP(1) Remarks, NoteDate,[exec].cname
FROM warrant_notes iNNER JOIN [exec] ON
cast(warrant_notes.AddedBy as varbinary) = cast(dbo.[exec].cid as varbinary)
WHERE WarrantID=@WarrantID AND AddedBy<>'Admin' ORDER BY NoteDate DESC
RETURN
END


Function returning one value in SQL Server


Create FUNCTION [dbo].[GetRoleDetais](@RoleID varchar(10)) 
returns varchar(50) 
AS 
BEGIN 
Declare @Roledetails as varchar(50)   
select @Roledetails=RoleTitle  FROM ProfileMaster WHERE ProfileID=@RoleID 
RETURN @Roledetails  
END


Hope this help you.

No comments:

Post a Comment