高手帮忙解决一下,sql语句的问题
declare @spbh varchar(20)
set @spbh = 'DAL100X% '
select * from openquery(zhangqingsong, 'select a.spbh,a.spmch,a.jlgg,a.dw,a.shpgg,a.shpchd,b.sl_kc from spkfk a,kc_spzkc b where a.spid = b.spid and a.spbh like ' '+@spbh+ ' ' ')
以上语句执行没有结果,但是
select * from openquery(zhangqingsong, 'select a.spbh,a.spmch,a.jlgg,a.dw,a.shpgg,a.shpchd,b.sl_kc from spkfk a,kc_spzkc b where a.spid = b.spid and a.spbh like ' 'DAL100X% ' ' ')
语句有执行结果,是不是单引号转义有问题
麻烦高手帮忙
------解决方案--------------------try
declare @spbh varchar(20)
set @spbh = 'DAL100X% '
EXEC( 'select * from openquery(zhangqingsong, ' 'select a.spbh,a.spmch,a.jlgg,a.dw,a.shpgg,a.shpchd,b.sl_kc from spkfk a,kc_spzkc b where a.spid = b.spid and a.spbh like ' ' ' ' '+@spbh+ ' ' ' ' ' ' ') ')