I am learning T-SQL syntax and I am very familiar with it, however how would I do the following:
We have a table that actually has a column that contains SQL statements. I want to build a SQL statement in Reporting Services that is going to take that column to build a "dynamic" SQL statment and then I will use the exec sp_executesql statement.
Do I need to declare a parameter, or in SQL is there such thing as a variable?
So if I have:
DECLARE @.sql nvarchar(4000)
SELECT AdHocSQL from TheTable
SET @.sql=AdHocSQL
Would this work? Is this syntatically correct? Or should I be doing this some other way?
The report is sort of a summary report that has about 250 different items and each item has different data to get from different tables.
Thanks for the information.
You 'almost' have it down.
Code Snippet
DECLARE @.SQL nvarchar(4000)
SELECT @.SQL = AdHocSQL
FROM MyTable
WHERE {criteria}
EXECUTE sp_executesql @.SQL
|||Thanks for the help. I do appreciate it.