Hi all...
I have a dynamic query as follow in stored procedure-
@EMPID int = NULL,
@ENAME varchar(50) = NULL
Declare @SQLQUERY as NVARCHAR(MAX)
set @SQLQUERY = 'Select * from EMP where 1=1'
if @EMPID IS NOT NULL
set @SQLQUERY = ' and EMP.ID ='+@EMPID
-----
Here I get an error-
Conversion failed when converting the nvarchar value 'select * From emp where EMP.ID=' to data type int.
Please help me out..
Thanks a lot.. in advance
Loading
Jignesh TrivediPosted Oct 10, 2013, 3:36 AM
I think , problem is, you are going to concat int and varchar value
problem is in below line.... (i think)
set @SQLQUERY = ' and EMP.ID ='+@EMPID
try
set @SQLQUERY = ' and EMP.ID ='+ CAST(@EMPID AS VARCHAR(10))
hope this will help you...
Riddhi ValechaPosted Oct 10, 2013, 11:53 PM
Thanks a lot ... to all...
@Jignesh Trivedi - Your solution worked out...Thanks A Ton !!
Sunny SharmaPosted Oct 10, 2013, 2:56 AM