Write down a Dynamic SQL Query with syntax in SQL?
Below is the query which is dynamic here in query we fetch some dynamic record from different variables and concat them to one string.
DECLARE @sqlCommand varchar(1000)
DECLARE @columnList varchar(75)
DECLARE @city varchar(75)
Set @columnList = 'FirstColumn1,SecondColumn,ThirdColumn'
Set @whereValue = '''Value'''
Set @sqlCommand = 'SELECT ' + @columnList + ' FROM tableName where Columnvalue= ' + @whereValue
EXEC(@sqlCommand)
| |