3 Incorporated comments; edited tags
source | link
@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 ?

I am using SQL Server. What am trying to do is to use stored procedure to for dynamic select statement and pass through by parameters, it is work fine till the where statement.

How I can treat @P_Input as character?

@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 ?

@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 ?

I am using SQL Server. What am trying to do is to use stored procedure to for dynamic select statement and pass through by parameters, it is work fine till the where statement.

How I can treat @P_Input as character?

2 added 46 characters in body
source | link

@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'

@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:

Incorrect syntax near '='.

Any suggestions ?

@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

@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 ?

1
source | link

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