"select Top 6 ID,Title from tb_Article as A where ID<>" + iID + " and exists(select * from (select SUBSTRING('" + strTags + "',number,CHARINDEX(',','" + strTags + "' + ',',number)-number) as v from master.dbo.spt_values where type = 'p' AND SUBSTRING(',' + '" + strTags + "',number,1)=',') AS T where CHARINDEX(v,A.Title)>0 or CHARINDEX(v,A.Tags)>0)"这是一个按照标签显示数据的语句!strTags=“中国,俄国”要求按照标签的先后顺序显示高手指导

解决方案 »

  1.   


    declare @a table (a int null,b varchar(10) null)
    insert into @a 
    select 1,'俄国' union all
    select 2,'中国' union all
    select 3,'美国' union all
    select 4,'法国'select * from @a order by charindex(b,'中国,法国,美国,俄国') asc--a   b
    --2 中国
    --4 法国
    --3 美国
    --1 俄国
      

  2.   

    order by charindex(','+col+',',','+中国,俄国+',')
      

  3.   

    order by charindex(colname,'中国,俄国') 
      

  4.   

    order by charindex(','+colname+',',',中国,俄国,')