Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the diff between Static Queries and Dynamic queries
give me some examples

Answer Posted / manoj

Static Queries are permanent and cannot be changed during run-time, like: "SELECT * FROM Employees"

Dynamic Queries can be changed during run-time as they are created by using variables and these variables contain parts of SQL Query, like:

DECLARE @SQL VARCHAR(MAX)
DECLARE @WHENSQL VARCHAR(2000)
DECLARE @SEARCHSQL VARCHAR(500)

SELECT @WHENSQL = 'EmployeeID'
SELECT @SEARCHSQL = '100'

SELECT @SQL = 'SELECT * FROM Employees WHERE ' + @WHENSQL + ' = ' + @SEARCHSQL

EXEC (@SQL)
-- or
EXEC sp_executesql @SQL


For more interview Questions on SQL Server: http://sqlwithmanoj.wordpress.com/interview-questions/

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know what is a with(nolock)?

1103


What is the difference between nvl and nvl2?

1028


What is 'Join' and explain its various types.

1211


How to check parameter value in stored procedure sql server?

1029


Explain what are the restrictions that views have to follow? : SQL Server Architecture

1099


What languages bi uses to achieve the goal?

1050


Does an index slow down updates on indexed columns?

1035


How to enter binary string literals in ms sql server?

1213


Describe in brief databases and sql server databases architecture.

1065


what are isolation levels? : Sql server database administration

1060


Explain system views?

1133


What is Transparent Data Encryption?

1061


What is the query and subquery?

1121


Can we join two tables without primary key?

1095


What is normalization? Explain its different types?

1153