In MSSQL, how do I create a reference variable to a table?

Posted by Jón Trausti on Stack Overflow See other posts from Stack Overflow or by Jón Trausti
Published on 2010-06-18T10:18:18Z Indexed on 2010/06/18 10:23 UTC
Read the original article Hit count: 287

Filed under:
|
|
|
|

Hello. I'm currently using sp_executesql to execute a T-SQL statement with a dynamic table name. 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 rather like to have is a TABLE variable of which is a reference to a table, so I could do for example:

UPDATE TableRef SET ... WHERE ...

Because when I have really long T-SQL statements it gets really hard to read due to the format of it within a string.

Any suggestions would be helpful.

Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about Microsoft