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

What is user defined stored procedures?

0 Answers  


What happens if an integer is too big for int date type?

0 Answers  


What are the limitation of the Online Index Rebuild Operation?

1 Answers  


How you can get a list of all the table constraints in a database?

0 Answers  


Explain ms sql server reporting services vs crystal reports?

0 Answers  






What do you understand by replication in sql server?

0 Answers  


what types of replication are supported in sql server? : Sql server database administration

0 Answers  


Does a sql server 2005 select statement require a from?

0 Answers  


What is the meaning of sql server?

0 Answers  


I have a table emp , Fields with empname,dnname,dno,salary. now I want copy distinct salary with all emp detail from emp into new table which is not already exist in database. how would I do this ?

2 Answers   Techno Labs,


How to get nth highest salary from employee table.

0 Answers  


I create a separate index on each column of a table. What are the advantages and disadvantages of this approach? : Sql server database administration

0 Answers  


Categories