I was just thinking of using a table variable instead of temp table to see if it gives any performance gain(no of records is less and I dont need any indexing on temp table) in a dynamic sql.
This is what I was trying to achieve:
DECLARE @SQLString NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)
DECLARE @tabvarO table(id int)
DECLARE @Lastlname varchar(30)
SET @SQLString = N'DECLARE @tabvar table(id int)
insert into @tabvar SELECT account_card_id
FROM t_account_card WHERE last_name = @Lastlname'
SET @ParmDefinition = N'@Lastlname varchar(30),@tabvar table(id int) OUTPUT'
@Lastlname = 'smith',
select * from @tabvarO
but I cant get the output in table variable and get error:
Msg 137, Level 15, State 2, Line 14
Must declare the scalar variable "@tabvarO".
I also understand that scope of variable for dynamic sql is for that statement only and that cannot be used outside the statement. But I'll appreciate any other inputs that might make it possible to get table variable out using dynamic sql.
Online Trainer For SQL DBA and Developer @RedBushTechnologies
with 16 yrs exp.