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

Explain about Views?

0 Answers   Infosys,


How to Handle the exceptions in Sqlsrver 2005??

3 Answers   Value Labs, Wipro,


Is SET a SQL Keyword?

4 Answers   BitWise,


How to use subqueries with the in operators in ms sql server?

0 Answers  


Explain what is cte (common table expression)?

0 Answers  






What does null mean?

0 Answers  


how to select a field with firstletter as capital and remaining are small letters

11 Answers  


Can sql server be linked with other servers like oracle?

0 Answers  


What is transact-sql ddl trigger?

0 Answers  


* CREATE TABLE [dbo].[t_Colors]([ColorId] [int] NOT NULL,[ColorName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ColorDesc] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[ColorIndex] [int] NULL) ON [PRIMARY] GO * insert into [t_Colors] values(101,'Red','',1) insert into [t_Colors] values(101,'Red1','',2) insert into [t_Colors] values(102,'Blue','',1) insert into [t_Colors] values(102,'Blue1','',2) insert into [t_Colors] values(102,'Blue2','',3) * In this table i need to delete DELETE FROM t_Colors WHERE ColorIndex=1 AND ColorId=102 After delete above condition i need to update the ColorIndex set to 1 for Blue1[ColorName] and 2 for Blue2[ColorName] select * from [t_Colors] Note:- how can i get updates the ColorIndex values after delete. for example we need to update Blue1 ColorIndex set to 1 and Blue2 ColorIndex set to 2

0 Answers  


Rate yourself in .NET and SQL ?

1 Answers   Cognizant, HCL, SunGard,


Explain identity in sql server?

0 Answers  


Categories