Monday, October 22, 2012

SQl Function for retuning values in tables from sql server


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER FUNCTION [dbo].[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

No comments:

Post a Comment