How do you insert the results of a dynamic SQL server query and a variable into the same row of a temp table.
Here is the format of the temporary table (#temp)
create TABLE #temp (YEAR INT, ACC_AMOUNT Money, REJ_AMOUNT Money, OUT_AMOUNT Money,TOT_AMOUNT Money)
The Stored PROC is executed by
exec sp_executesql @pSQL
and will return values that should go into the columns ACC_AMOUNT, REJ_AMOUNT, OUT_AMOUNT.
14569849.11 696235.49 1353464.92 16619549.52
I want to insert a variable (@pACCU_YEAR) for the Year and the results of the SP and insert the dyanmic query in the same Row. This is wrong, but this will give you an idea of what I mean.
insert into #temp (YEAR)
values (@pACCU_YEAR)
insert into #temp (ACC_AMOUNT , REJ_AMOUNT, OUT_AMOUNT,TOT_AMOUNT)
exec sp_executesql @pSQL
This will result in
YEAR ACC_AMOUNT REJ_AMOUNT OUT_AMOUNT TOT_AMOUNT
2014 NULL NULL NULL NULL
NULL 14569849.11 696235.49 1353464.92 16619549.52
I would like:
YEAR ACC_AMOUNT REJ_AMOUNT OUT_AMOUNT TOT_AMOUNT
2014 14569849.11 696235.49 1353464.92 16619549.52
@pSQL?