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 many types of local tables are there in sql server?
What is buffer cash and log cache in sql server?
Do you know what are different types of replication in sql server?
What happens if null values are involved in datetime operations?
How can i Relate Tables in SSIS
between cast and convert which function would you prefer and why?
What is join query?
How to backup SQL Server Reporting Services ?
Explain about thread and memory management process of SQL?
Can you explain what is sql server english query?
What is 1nf 2nf and 3nf?
What are types of scd? : sql server analysis services, ssas
How to see the event list of an existing trigger using sys.trigger_events?
What are the dmvs?
How do I find the sql server instance name?