Solved

t-sql query

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

708 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

12 Experts available now in Live!

Get 1:1 Help Now