Solved

t-sql query

Posted on 2014-01-21
2
248 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS 2013 - Creating a summarized report 19 33
Simple SQL query from two tables 13 53
Query Help - MSSQL - Averages 5 26
Update a text value in another table 10 39
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

776 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