I'm really new to T-SQL, so this is probably a really easy question, but here goes:
I'm trying to create a function that selects builds a string specifying a table to select from:
SELECT * FROM ('AdventureWorks.sys.schemas')
That's what I want to do, but it gives me:
Incorrect syntax near 'AdventureWorks.sys.schemas'.
Basically, I need to know how to convert from a string to a table type. Hopefully this is easy.
Thanks a bunch!
In order to do that you will need dynamic sql, but because you mentioned that you are new, I will recomend to stay away from it by now and move forward in learning T-SQL.
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html
AMB
|||You can't 'convert' from a string to a table type. As Alejandro indicates, using dynamic SQL may be the only viable option.
As you will discover upon reviewing Erland's article (see link above), using dynamic SQL has quite a few security issues, and if used improperly, may jepardize the safety and security of your server and data.
No comments:
Post a Comment