Function Error

  • In the function given below, i want to replace SIS with function variable @DBName.How can i do this??

    CREATE Function salesVolumeCompare(@ID int,@Year int,@DBName varchar(40))

    RETURNS bigint

    AS

    BEGIN

    DECLARE @vol BIGINT,@sqlSTR varchar(40)

    SET @sqlSTR=SIS.dbo.salesVolume(@ID, @Year)

    --SET @vol=CAST((SELECT SF.dbo.salesVolume(@ID, @Year)  FROM tblSalesItem WHERE  tblSalesItem.ID = @ID) AS bigint)

    SET @vol=CAST((SELECT @sqlSTR  FROM tblSalesItem WHERE  tblSalesItem.ID = @ID) AS bigint)

    if @vol is null

     SET @vol = 0

    RETURN (@vol)

    END

     

     

  • You can't do that. You need to use sp_executesql to fetch output values from dynamic sql, and you need to use a stored proc to do that. Sorry I don't have any exemples of that.

  • Thanks!!

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

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