帮忙看这条语句错在那里
declare @m_t varchar(50)
declare @m_t1 varchar(50)
exec('update book set 总金额=(select sum(价格) from '+@m_t+' where 价值>=50 and
name in (select 编号 from t1 where name='+@m_t1+')')
执行这条语句,报@m_t1,没有声明的错误,@m_t 为一个表名,@m_t1为字符变量
------解决方案--------------------变量赋值啦? 还有生命的时候给变量个默认值试试 declare @m_t varchar(50)=''
------解决方案--------------------declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='你要查询的表名' --要赋值的
set @m_t1='你要查询的名字'
exec('update book set 总金额=(select sum(价格) from '+@m_t+' where 价值>=50 and
name in (select 编号 from t1 where name='+@m_t1+')')
------解决方案--------------------declare @m_t varchar(50)
SET @m_t=表名称
declare @m_t1 varchar(50)
SET @m_t1=[NAME]值
PRINT 'update book set 总金额=(select sum(价格) from '+@m_t+' where 价值>=50 and
name in (select 编号 from t1 where name='+@m_t1+')'