Tuesday, August 2, 2011

Execute query with string

Today, I got a strange requirement to have the query as query string to execute, and tried various ways and found that the simplest way to do this is

Declare @temp Varchar(500)
Set @temp = ‘Select * From Employees’
Exec (@temp)

the above code will help us in adding or removing the clause from the query