喜欢运营商问题'maha,delhi'

时间:2011-12-02 07:47:04

标签: mysql sql

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的结果。

1 个答案:

答案 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))