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
Do you know what is a with(nolock)?
What is the difference between nvl and nvl2?
What is 'Join' and explain its various types.
How to check parameter value in stored procedure sql server?
Explain what are the restrictions that views have to follow? : SQL Server Architecture
What languages bi uses to achieve the goal?
Does an index slow down updates on indexed columns?
How to enter binary string literals in ms sql server?
Describe in brief databases and sql server databases architecture.
what are isolation levels? : Sql server database administration
Explain system views?
What is Transparent Data Encryption?
What is the query and subquery?
Can we join two tables without primary key?
What is normalization? Explain its different types?