Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Sunday, March 11, 2012

declaring a variable

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.

Friday, February 24, 2012

Debugging SQL

Hi All
win 2k(pro0 sql server 2k (dev ed) asp-vbscript
I'm still learning how to code in SQL... I've found the "Debug"
command in QA for debuging stored procs but I cant seem to debug other
stuff... functions, triggers etc. I cant even debug code in the QA
that I write to test before I put the final version in a store proc.
Is there anyway of debugging at least the batch sql code I write in
the QA before I put it in the store proc... any 3rd party software if
cant be done in QA? or do I have to write it and put it in a stored
proc then debug it? how do you pros do it?
thanks for any info.
AlYou can debug triggers is you execute the DML statement (Insert, Update or
Delete) that fires the trigger inside a SP - then you can debug the SP. The
same is true for a UDF - call if from a SP. VS.NET IDE has debugger as well.
--
Dejan Sarka, SQL Server MVP
FAQ from Neil & others at: http://www.sqlserverfaq.com
Please reply only to the newsgroups.
PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Harag" <harag@.softhome.net> wrote in message
news:v703mvgc4h59u8hcn0d32k8fk8p777kle0@.4ax.com...
> Hi All
> win 2k(pro0 sql server 2k (dev ed) asp-vbscript
> I'm still learning how to code in SQL... I've found the "Debug"
> command in QA for debuging stored procs but I cant seem to debug other
> stuff... functions, triggers etc. I cant even debug code in the QA
> that I write to test before I put the final version in a store proc.
> Is there anyway of debugging at least the batch sql code I write in
> the QA before I put it in the store proc... any 3rd party software if
> cant be done in QA? or do I have to write it and put it in a stored
> proc then debug it? how do you pros do it?
> thanks for any info.
> Al