动态语句中加入整形变量,执行报错
declare @m_xh int
declare @sql varchar(1000)
@m_xh =1
set @sql='update khb set khb.金额=b.金额 from khb,( select '+@m_xh+' as 序号,sum(佣金) as 金额 from kh ) b where khb.序号=b.序号'
exec(@sql)
执行报
select '' 转换为数据类型为 int 的列时发生语法错误。,谁知道整形变量该怎么加啊
[解决办法]
declare @m_xh int
declare @sql varchar(1000)
SET @m_xh =1
set @sql='update khb set khb.金额=b.金额 from khb,( select '+RTRIM(@m_xh)+' as 序号,sum(佣金) as 金额 from kh ) b where khb.序号=b.序号'
exec(@sql)
[解决办法]
declare @m_xh int declare @sql varchar(1000) @m_xh =1 set @sql='update khb set khb.金额=b.金额 from khb,( select '+cast(@m_xh as varchar)+' as 序号,sum(佣金) as 金额 from kh ) b where khb.序号=b.序号'