帮忙看下语句还是报错
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
update tj set 总金额=(select sum(价格) from '+@m_t+' where 价格>=50 and
账号 in (select 编号 from buy_book where name='''+@m_t1+''')
执行报错
服务器: 消息 170,级别 15,状态 1,行 5
第 5 行: '+@m_t+' 附近有语法错误。
[解决办法]
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
declare @str varchar(max)
set @str='
update tj set 总金额=(select sum(价格) from '+@m_t+' where 价格>=50 and
账号 in (select 编号 from buy_book where name='''+@m_t1+''')
'
exec( @str)
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
DECLARE @sql VARCHAR(max)
SET @sql='update tj set 总金额=(select sum(价格) from '+@m_t+' where 价格>=50 and
账号 in (select 编号 from buy_book where name='''+@m_t1+'''))'
EXEC(@sql)
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
declare @str varchar(max)
set @str='
update tj set 总金额=(select sum(价格) from '+@m_t+' where 价格>=50 and
账号 in (select 编号 from buy_book where name='''+@m_t1+'''))
'