sql 单引号 问题?????
declare @ab varchar(24)
set @ab = '123'
select * from OPENQUERY(ORCL,
'select *
from TEST
WHERE STORECD = ''0093'' and PRONO= '''+@ab+''' ')
我在SQLserver 上 执行上面 语句 抽出的是Oracle的数据
其中 PRONO 条件是变量
为啥 老提示 + 附近 有错误那??
Sqlserver中 怎么字符串拼接??
望大虾 解答
------解决方案--------------------declare @ab varchar(24)
set @ab = '123'
select * from OPENQUERY(ORCL,
'select *
from TEST
WHERE STORECD = ''0093'' and PRONO= ' +@ab+ ' ')
------解决方案--------------------TRY:
declare @ab varchar(24)
set @ab = '123'
EXEC('
select * from ORCL.DBNAME..TEST
WHERE STORECD = ''0093'' and PRONO= '''+@ab+''' ')
使用链接服务器,OPENQUERY得第二个参数只能是字符串常量
------解决方案--------------------改成在外面判断呢
select * from OPENQUERY(ORCL,'select * from TEST WHERE STORECD = ''0093'' ')
where PRONO=@ab
------解决方案--------------------动态参数的,需要拼接运行
declare @ab varchar(24),@sql VARCHAR(max)
set @ab = '123'
SET @sql='select * from OPENQUERY(ORCL, ''select *from TEST WHERE STORECD = ''''0093'''' and PRONO= '''''+@ab+''''''')'
--PRINT @sql
EXEC (@sql)
------解决方案--------------------字符串里面两个单引号代表一个单引号