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
What is data compression?
What is 5nf in normalization form?
How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?
Explain why variables called the most powerful component of ssis?
What is data source in connection string?
What is dbcc?
Explain few examples of stored procedure over triggers?
What is “begin trans”, “commit tran”, “rollback tran” and “savetran”?
How do I find the sql server version?
What is resource governor in sql server?
as a part of your job, what are the dbcc commands that you commonly use for database maintenance? : Sql server database administration
What is the use of nvl work?
What are the results of running this script?
Explain how to integrate the ssrs reports in application?
where can you add custom error messages to sql server? : Sql server administration