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

Answers were Sorted based on User's Feedback



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

Answer / praveen

Static queries are the queries we normally use like SELECT *
FROM EMPLOYEE. where as dynamic queries can be built and
executed dynamically. sp_executesql system stored procedure
is used to execute dynamic sql statements.

Eg: sp_executesql N'select * from employee'

dynamic sql queries will take more time to execute when
compared to static queries

Is This Answer Correct ?    18 Yes 5 No

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

Answer / 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

More SQL Server Interview Questions

Hi Friends, I have a table in which there are thousands of records and in city field there is NULL value for all records now i want to change that null value with distinct values in each record say delhi, bihar, agra, jaipur etc, what will be the query for that????? its not possible to update thousands of records one by one. is there any alternative ...? Plz help ... its urgent Thanx in advance

1 Answers  


What is ddl command?

0 Answers  


What is service broker?

0 Answers  


Explain syntax for disabling triggers?

0 Answers  


What is collation sensitivity?

0 Answers  






What are the different types of replication are there in sql server 2000?

0 Answers  


1.what is the diff between nolock optimizer and read uncommitted isolation? 2.what is the diff between revoke and deny? 3.what is percieved down time? 4.whether password protection are required for backups?if yes why?if no why? 5.what is fill factor? 6.what is cost analysis? 7.what is mean by piece meal restore? 8.what is 'rowguidcol'? 9.impersonate permission? 10.what is selectivity?

0 Answers  


what is the signification difference of this bit data type between sql 6.5 and later version sql server?

1 Answers  


How we can refresh the view?

0 Answers  


what is denormalization and when would you go for it? : Sql server database administration

0 Answers  


What is a benefit of using an after insert trigger over using a before insert trigger?

0 Answers  


How reterive duplicate value in SQL?

6 Answers  


Categories