Declare @PackageID varchar(50)
Declare @state varchar(50)
set @PackageID='2,4,5'
set @state='delhi,maha'
select DetailsID,Industry,StateID from DetailsMaster
where ((Industry IN (SELECT * from fnList2Table (@PackageID)))
or
((StateID like '%' +(SELECT top 1 [s] from dbo.Split(',', @state)) + '%')
))
Union
select DetailsID,Industry,StateID from DetailsMaster
where ((Industry IN (SELECT * from fnList2Table (@PackageID)))
or
((StateID like '%' +(SELECT top 1 [s] from dbo.Split(',', Reverse(@state))) + '%')
))
上述查询不是状态kk,maha
的结果。它将获取maha,kk
的结果。
答案 0 :(得分:3)
您的Reverse(@state)
似乎未将delhi,maha
切换为maha,delhi
。
Reverse实际上做的是将delhi,maha
转换为aham,ihled
。
您可以尝试使用substr_index自行剪切字符串,然后使用concat_ws反向重新组合:
CONCAT_WS(',', SUBSTRING_INDEX(@state,',',-1), SUBSTRING_INDEX(@state,',',1))