Problem with variable table in SQL
-
Hi all, I've got the following function: CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE ( ................. ) AS BEGIN DECLARE @MyTable TABLE ( ............. ) INSERT INTO @MyTable SELECT ...... FROM AnotherTable1 Inner Join AnotherTable2 ....... INSERT INTO @ReturnTable SELECT ...... FROM ( SELECT ...... FROM @MyTable WHERE ....... UNION SELECT ...... FROM @Table WHERE ...... ) RETURN END When i call this function, an error message appears "Must declare the scalar variable "@MyTable"." Please help me work out this problem Thanks so much
-
Hi all, I've got the following function: CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE ( ................. ) AS BEGIN DECLARE @MyTable TABLE ( ............. ) INSERT INTO @MyTable SELECT ...... FROM AnotherTable1 Inner Join AnotherTable2 ....... INSERT INTO @ReturnTable SELECT ...... FROM ( SELECT ...... FROM @MyTable WHERE ....... UNION SELECT ...... FROM @Table WHERE ...... ) RETURN END When i call this function, an error message appears "Must declare the scalar variable "@MyTable"." Please help me work out this problem Thanks so much
-
vuthaianh wrote:
CREATE FUNCTION Test(....) RETURNS @ReturnTable TALBE
There's a typo here.
vuthaianh wrote:
SELECT ...... FROM @Table WHERE ......
Where is @Table declared?
Paul Marfleet
-
Hi pmarfleet, Sorry, i made a typing mistake @Table must be @MyTable But the error does still appear. Thanks again
-