Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am altering `function` like:
SQL
ALTER FUNCTION [dbo].[fn_CalculateListing](@Listing TypeListingDatePrice READONLY)
RETURNS TypePreviousListingResult
AS
BEGIN
    DECLARE @tbl_ListingDateDetails TypePreviousListingResult
    RETURN @tbl_ListingDateDetails
END
GO

But throwing error as:

SQL
Msg 137, Level 16, State 1, Procedure fn_CalculateListing, Line 6
   Must declare the scalar variable "@tbl_ListingDateDetails".

Why this giving error and asking for declaration eventhough I have declared that before using that variable?
Posted
Updated 24-Jan-16 19:09pm
v2

1 solution

That isn't your whole function - if nothing else it doesn't give a value to the variable so the RETURN is a little pointless! :laugh:
Without the whole function it's difficult to be sure (and since we don't have your types, we can't test your code exactly) but the most common reason for this is that your function contains one or more GO commands. These "break" the code and anything declared above the GO is not available below:
SQL
DECLARE @X INT
SET @X = 3
SELECT @X
GO
SELECT @X
Will give the error message you describe.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900