Error in My Function Syntax

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply