I'm looking for some views on how to go about resolving this challenge. I have a variable say @Var1
which holds a SQL statement within it.
Example
@Var1 = `SELECT * from another_table WHERE City IS NOT NULL AND Address IS NOT NULL`
When I execute this variable
EXECUTE sp_executesql @Var1
I get the desired result, City and Address excluding NULL values.
I am hoping to update a existing table (tbl1) based on execution result of @Var1
:
Something like:
UPDATE TABLE tbl1 AS (EXECUTE sp_executesql @Var1)
Is something like this even possible? Or what approach can I take to get the result of @Var1
into tbl1
?
Thanks in advance.