June 16, 2010 at 2:55 am
ALTER Function [dbo].[fn_InvoiceList]
(@CustName nvarchar(50),
@InvoiceDate datetime)
RETURNS TABLE
AS
RETURN
IF (@CustName IS NULL) or (@InvoiceDate Is Null)
BEGIN
print 'Name Or Date Is Null'
END
ELSE
BEGIN
Print ' All Data To Be Displayed'
END
June 16, 2010 at 3:45 am
If your function states RETURNS TABLE (inline table valued function), what must follow the RETURNS statement is a single select statement, nothing else. If you want IF statements, you need a multstatement table valued function (and these often don't perform well) where you define the structure of the table that you return, then populate it and return it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply