0
votes

I want to set @inputData as the rows of a select statement, then pass it into my DoSomething stored procedure:

DECLARE @inputData [dbo].[TestTableType];

SET @inputData = ( 
    SELECT
        1 AS Client_Id,
        20170202 AS a,
        18595 AS b,
        49.82 AS c,
        88 AS d,
        31 AS e,
        0.67 AS f,
        0 AS g,
        44 AS h,
        1827 AS i,
        5 AS j,
        87 AS k
);

EXEC DoSomething @inputData;

But I get this error:

Msg 137, Level 16, State 1, Line 3
Must declare the scalar variable "@inputData".

What am I doing wrong?

2
Note sure, maybe try insert into @inputData select ...user1429080
Thanks @user1429080 Works perfectly!Jimmyt1988

2 Answers

4
votes

You don't SET table variables. You INSERT into them:

INSERT INTO @inputData /* Should have column list here also */
SELECT
        1 AS Client_Id,
        20170202 AS a,
        18595 AS b,
        49.82 AS c,
        88 AS d,
        31 AS e,
        0.67 AS f,
        0 AS g,
        44 AS h,
        1827 AS i,
        5 AS j,
        87 AS k
;
1
votes

Try with INSERT INTO. Think of a table type as literally a temp table (it basically is).

DECLARE @inputData AS TestTableType

INSERT INTO @inputData 
SELECT
    1 AS Client_Id,
    20170202 AS a,
    18595 AS b,
    49.82 AS c,
    88 AS d,
    31 AS e,
    0.67 AS f,
    0 AS g,
    44 AS h,
    1827 AS i,
    5 AS j,
    87 AS k
);