Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using Dynamic SQL (Simple question - hopefully)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

112 Posts

Posted - 01/04/2013 :  11:54:10  Show Profile  Reply with Quote
Is it possible to execute a dynamically created SQL statement that is stored in a variable in a regular SQL statement? (I'm considering creating a function but I thought I'd find out just in case.)

I have a tedious Statement that would be better created dynamically rather than manually. I'd like to use it in as a subquery perhaps.

Suppose I had a statement such as (just a simple example i suppose)


Of course something that simple i could just write out but i assume any type of complex string operation would be same regardless.

Flowing Fount of Yak Knowledge

8781 Posts

Posted - 01/04/2013 :  12:20:15  Show Profile  Visit webfred's Homepage  Reply with Quote
see here:

Too old to Rock'n'Roll too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000