dukeslater
Technical User
My understanding is that variables of table datatype remain in scope until the completion of the stored procedure, and all the examples I've found are very similar to this piece of my procedure:
declare @v_restable table(tran_date smalldatetime, rescount int)
insert into @v_restable
select date, number from some table...
update table 2
set table2.field1 = @v_restable.rescount
from @v_restable INNER JOIN table2
on @v_restable.tran_date = table2.date
However, when it hits the line that begins "set table2.field..." I get the error message that says "Must declare the variable @v_restable."
This same syntax works fine with a temp table, but I'd like to know how to do this with a variable. What am I missing?
Thanks...
declare @v_restable table(tran_date smalldatetime, rescount int)
insert into @v_restable
select date, number from some table...
update table 2
set table2.field1 = @v_restable.rescount
from @v_restable INNER JOIN table2
on @v_restable.tran_date = table2.date
However, when it hits the line that begins "set table2.field..." I get the error message that says "Must declare the variable @v_restable."
This same syntax works fine with a temp table, but I'd like to know how to do this with a variable. What am I missing?
Thanks...