我需要生成输出:
"word1" AND "word2" OR "word3 word4"
来自此输入字符串:
word1 AND word2 OR word3 word4
到目前为止:
DECLARE
@string NVARCHAR(2000)
SET @string = 'word1 , word2 | word3 word4'
SET @string = REPLACE(REPLACE( @string , ',' , ' AND ' ), '|' , ' OR ' )
SELECT QUOTENAME(@string,'"')
对此有什么可行的解决方案?
答案 0 :(得分:1)
这似乎是一个非常奇怪的要求。以下SQL将执行此操作:
select '"'+replace(replace(col, ' AND ', '" AND "'), ' OR ', '" OR "')+'"'
from (select 'word1 AND word2 OR word3 word4' as col) t;
您也可以在没有子查询的情况下执行此操作:
set @string = '"'+replace(replace(@string, ' AND ', '" AND "'), ' OR ', '" OR "')+'"';