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)