1.

Write down a Dynamic SQL Query with syntax in SQL?

Answer»

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)



Discussion

No Comment Found