Using Table data type in a local variable in a sql server 2008 stored procedure

I'm using table type in my variable @temporaltable

FETCH MyCursor Into @temporaltable 

but when I try to get on e field I got an error...

insert into T1 (t1field1,t1field2, t1field3) 
values(@temporaltable.field1, @temporaltable.field2, @temporaltable.field3)   

it doesn't recognize @temporaltable and I got error

Must declare the scalar variable @temporaltable

Answers


This syntax should help, obviously substituting for correct data types, tables names and select statements.

DECLARE @myTable TABLE 
( 
    ... 
) 

DECLARE @var1 [DataType]
DECLARE @var2 [DataType]
DECLARE @var3 [DataType]

DECLARE myCursor CURSOR LOCAL FAST_FORWARD FOR
    SELECT ....
    FROM .....
OPEN myCursor

FETCH NEXT FROM myCursor INTO @var1, @var2, @var3

WHILE @@FETCH_STATUS = 0 BEGIN
    INSERT INTO T1 ([Col1], [Col2], [Col3]) VALUES (@var1, @var2, @var3)

    FETCH NEXT FROM myCursor INTO @var1, @var2, @var3
END

CLOSE myCursor
DEALLOCATE myCursor

Need Your Help

jQuery ajaxError() handler fires if user leaves page before page finishes loading

jquery ajax global handler

We use jQuery's global ajaxError() handler to alert the user of any AJAX failures: