当前位置: 代码迷 >> Sql Server >> 请问!中
  详细解决方案

请问!中

热度:45   发布时间:2016-04-27 19:06:08.0
请教!急中!
DECLARE   @chrsql   char(1000),@Warehouse   char(1000)

set   @Warehouse= '工程 '
set   @Warehouse   = '% '[email protected]+ '% '


set   @chrsql= 'select   *   into   tempdb..table_csyy   from   tempdb..table1 '+ '   where '+ '   仓库名称 '+ '   like   '+char(39)[email protected]+char(39)

print   @chrsql

结果为:


select   *   into   tempdb..table_csyy   from   tempdb..table1   where   仓库名称   like   '%工程

为什么后面的没有成功连起来
结果应该是:
select   *   into   tempdb..table_csyy   from   tempdb..table1   where   仓库名称   like   '%工程% '

------解决方案--------------------
DECLARE @chrsql char(1000),@Warehouse char(1000)
set @Warehouse= '工程 '

set @Warehouse = '% '+rtrim(@Warehouse)+ '% ' ' '


set @chrsql= 'select * into tempdb..table_csyy from tempdb..table1 '+ ' where '+ ' 仓库名称 '+ ' like '+char(39)[email protected]

print rtrim(@chrsql)
  相关解决方案