I am currently using sp_executesql to execute a T-SQL statement with the name of a dynamic table. However, it is really ugly to see something like:
set @sql = 'UPDATE '+Table_Name+' SET ... WHERE '+someVar+' = ... AND '+someVar2' = ...' sp_executesql @sql
What I would like to have is a TABLE variable, which is a table reference, so I could do, for example:
UPDATE TableRef SET ... WHERE ...
Because when I have very long T-SQL statements, it is very difficult to read because of its format inside the string.
Any suggestions would be helpful.
variables sql sql-server tsql dynamic-sql
JΓ³n trausti
source share