我创建了以下程序:
CREATE procedure getdata ( @ID int,@frm varchar(250),@to varchar(250) ) AS BEGIN DECLARE @sql nvarchar(500) set @sql = 'select' set @sql = @sql + ' EmpName,Address,Salary from Emp_Tb where 1=1 ' IF (@ID <> '' and @ID is not null) Begin SET @sql=@sql+' AND Emp_Id_Pk=' +@ID End END print @sql --execute (@sql)
我尝试执行它:
**execute getdata 3,'','';**
但是我收到以下错误:
Conversion Failed when converting the nvarchar value ‘select EmpName,
Address,Salary from Emp_Tb where 1=1 AND Emp_Id_Pk=’ to data type int
请帮忙.