Solved

t-sql query

Posted on 2014-01-21
2
246 Views
Last Modified: 2014-01-22
I'm using sql server 2008 R2.

I was looking at a sql server query and I noticed that it was using a notation that looked like this.
This is a snippet from the full query. I noticed that a variable was declared and then some sql statements where enclosed in parentheses and assigned to that variable.

snippet from query
What is the technical name for this style or technique?
Do you have a link to a website or book that covers writing a query in this fashion.

What are the pros and cons or writing a sql query this way?
0
Comment
Question by:maqskywalker
2 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 39798770
What is the technical name for this style or technique?
Dynamic SQL

What are the pros and cons or writing a sql query this way?
Erland goes to great lengths to describe the the pros and cons of using Dynamic SQL in
The Curse and Blessings of Dynamic SQL  For the most part, except for some edge cases it should not be used.
0
 
LVL 2

Assisted Solution

by:jaLouden
jaLouden earned 250 total points
ID: 39798789
Hey maqskywalker

This look like it is about to execute sp_executesql.  Basically you assign a command to a varible  and then execute

sp_executesql @command

have a look at Pinal Dave's blog

http://blog.sqlauthority.com/2007/07/02/sql-server-2005-comparison-sp_executesql-vs-executeexec/ 

for more detail about the commentary about the can and can nots

Cheers
JL
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now