SQL错误:转换nvarchar值时转换失败

SQL错误:转换nvarchar值时转换失败,sql,sql-server,tsql,stored-procedures,Sql,Sql Server,Tsql,Stored Procedures,我正试图编写一个相当简单的存储过程,但当我print@sql set @where = ' where deliverydate between '''+ @FromDate + ''' and ''' + @ThruDate + '''' set @where = @where + ' and custlocation = '+ @custlocationID + '''' 错误内容如下: 将nvarchar值“其中deliverydate介于“8/1/2013”和“8/20/2014”

我正试图编写一个相当简单的存储过程,但当我
print@sql

set @where = ' where deliverydate between '''+ @FromDate + ''' and ''' + @ThruDate + ''''
set @where = @where + ' and custlocation = '+ @custlocationID + ''''  
错误内容如下:

将nvarchar值“其中deliverydate介于“8/1/2013”和“8/20/2014”之间且custlocationID=”转换为数据类型int时,转换失败

@custlocationID
声明为
int


有人能帮忙处理撇号吗?

引起错误消息的不是撇号。您正在尝试添加字符串和整数,这将隐式地将字符串转换为整数

在连接整数之前将其强制转换为字符串:

set @where = @where + ' and custlocation = ' + cast(@custlocationID as varchar)