读书人

请问!中

发布时间: 2012-02-26 20:19:44 作者: rapoo

请教!急中!
DECLARE @chrsql char(1000),@Warehouse char(1000)

set @Warehouse= '工程 '
set @Warehouse = '% '+@Warehouse+ '% '


set @chrsql= 'select * into tempdb..table_csyy from tempdb..table1 '+ ' where '+ ' 仓库名称 '+ ' like '+char(39)+@Warehouse+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)+@Warehouse

print rtrim(@chrsql)

读书人网 >SQL Server

热点推荐