Solved

t-sql query

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

ClickHouse in a General Analytical Workload

We have mentioned ClickHouse in some recent posts, where it showed excellent results.

In this article on Experts Exchange, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

631 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