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
How to delete multiple rows with one delete statement in ms sql server?
What is the difference between indexing and hashing?
What is the difference between sdf and mdf?
How do I start sql server agent automatically?
How to find index size for each index on table?
What is the purpose of update statistics and scope_identity() function?
what are the different ways of moving data/databases between servers and databases in sql server? : Sql server database administration
what's the information that can be stored inside a bit column? : Sql server database administration
How many triggers you can have on a table?
Will count(column) include columns with null values in its count?
what is database replicaion? What are the different types of replication you can set up in sql server? : Sql server database administration
what is the difference between Delete and Truncate command in SQL
What is an indexed view?
Explain the difference between delete,drop and truncate in SQL Server?
Does sql server use t sql?