1 of 3
Lanaa
  • 31
  • 1
  • 6

Dynamic Select with error in where conditon

@P_SqLCommand NVARCHAR(100) OUTPUT, --output which will be return @P_SqlList NVARCHAR(30),-- columns that needs to be filtered out @P_Table NVARCHAR(30),--Table Name needs to be use in the select statment @P_Input NVARCHAR(50),--the filter variable @P_Num varchar(5) SET @P_Input='@P_Input'

SET @P_SqLCommand='SELECT Top '+ @P_Num +' '+@P_SqlList+'  FROM '+
@P_TABLE +' where '+ @P_SqlList + '=' + @P_Input;

give me an error Incorrect syntax near '='. ANY suggestions

Lanaa
  • 31
  • 1
  • 6