Solved

t-sql query

Posted on 2014-01-21
2
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 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