Riddhi Valecha

Riddhi Valecha

  • 422
  • 3.3k
  • 415.5k

Dynamic SQL Query

Oct 10 2013 1:31 AM
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

Answers (3)