看看语句错在那里
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
exec('select sum(总金额) from '+@m_t+' where 价格>=50 and
name in (select 编号 from buybook where name='+@m_t1+')')
执行报列名无效的错误
服务器: 消息 207,级别 16,状态 3,行 1
列名 '张三' 无效。
------解决方案--------------------糾正如下:
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
exec('select sum(总金额) from '''+@m_t+''' where 价格>=50 and
name in (select 编号 from buybook where name='+@m_t1+')')
------解决方案--------------------上面錯了,應是糾正如下:
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
exec('select sum(总金额) from '+@m_t+' where 价格>=50 and
name in (select 编号 from buybook where name='''+@m_t1+''')')
------解决方案--------------------運行以下你就會明白了:
declare @m_t varchar(50)
declare @m_t1 varchar(50)
set @m_t='book'
set @m_t1='张三'
select 'select sum(总金额) from '+@m_t+' where 价格>=50 and
name in (select 编号 from buybook where name='''+@m_t1+''')'
select 'select sum(总金额) from '+@m_t+' where 价格>=50 and
name in (select 编号 from buybook where name='+@m_t1+')'
------解决方案--------------------