select PATINDEX('%[吖-座]%',s) as [index],left(s,PATINDEX('%[吖-座]%',s)-1) as s1,stuff(s,1,PATINDEX('%[吖-座]%',s)-1,'') as s2以上语句可以实现,但当该字段中的字符串不包括汉字的时候,就会出错,如何处理呢。即当字符串中不包括汉字时,就让其为空。

解决方案 »

  1.   

    select 
    PATINDEX('%[吖-座]%',s) as [index],
    case 
        when PATINDEX('%[吖-座]%',s) > 0
        then left(s,PATINDEX('%[吖-座]%',s)-1)
    end as as s1,
    case
        when PATINDEX('%[吖-座]%',s) > 0
        then stuff(s,1,PATINDEX('%[吖-座]%',s)-1,'') 
    end as s2
      

  2.   

    抱歉,更正一下."end as as s1"应为"end as s1",多了一个as:
    select 
    PATINDEX('%[吖-座]%',s) as [index],
    case 
        when PATINDEX('%[吖-座]%',s) > 0
        then left(s,PATINDEX('%[吖-座]%',s)-1)
    end as s1,
    case
        when PATINDEX('%[吖-座]%',s) > 0
        then stuff(s,1,PATINDEX('%[吖-座]%',s)-1,'') 
    end as s2