Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

dynamic sql query?/ Expand / Collapse
Author
Message
Posted Monday, September 2, 2013 12:17 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 3:08 AM
Points: 68, Visits: 409
where we use dynamic sql queries??
in my office we don't use dynamic sql queries but I am want to know in which case it finds application??
if possible give an example
Thanks
Post #1490522
Posted Monday, September 2, 2013 6:32 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
gurjer48 (9/2/2013)
where we use dynamic sql queries??
in my office we don't use dynamic sql queries but I am want to know in which case it finds application??
if possible give an example
Thanks


http://www.sommarskog.se/dynamic_sql.html
Post #1490604
Posted Monday, September 2, 2013 7:02 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 5:18 AM
Points: 42,417, Visits: 35,481
As little as possible, only where absolutely necessary and after having paid careful attention to the risks of SQL Injection.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1490614
Posted Friday, September 6, 2013 2:52 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, July 18, 2014 6:56 AM
Points: 553, Visits: 2,574
Erland's article, "The Curse and Blessings of Dynamic SQL" (the link that OTF inlcuded) is the best I have ever read about DSQL.

Itzek Ben Gan's Microsoft® SQL Server 2012 T-SQL Fundamentals* includes a good summary of when Dynamic SQL can be helpful:

Dynamic SQL is useful for several purposes, including:

■ Automating administrative tasks For example, querying metadata and constructing and executing a BACKUP DATABASE statement for each database in an on-premises instance

■ Improving performance of certain tasks For example, constructing parameterized ad-hoc queries that can reuse previously cached execution plans...

■ Constructing elements of the code based on querying the actual data For example, constructing a PIVOT query dynamically when you don’t know ahead of time which elements should appear in the IN clause of the PIVOT operator


* I know we are in the 2008 forum but all of the above is relevant to 2008 as well.


-- Alan Burstein



Read this article for best practices on asking questions.
Need to split a string? Try this (Jeff Moden)
Need a pattern-based string spitter? Try this (Dwain Camps)
My blog
Post #1492429
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse