select a from A where a not in (select a from B ) 
order by cast( substring(a,2,charindex('-',a)-1) as int) 

解决方案 »

  1.   

    select a 
    from A 
    where a not in (select a from B ) 
    order by cast (substring(a,2,len(a)-3)  as int )
      

  2.   

    select a from A where a not in (select a from B) 
    order by cast(substring(a,2,charindex('-',a)-1 -1) as int) 
      

  3.   

    select a  
    from A t 
    where  not exists(select 1 from B where t.a = a )  
    order by cast (substring(a,2,len(a)-3)  as int ) 
      

  4.   

    如果:第一位是字母,然后是序号,最后加"-"和加一个字母 上述内容固定可直接:select a from A where a not in (select a from B ) 
    order by cast(substring(a,2,len(a)-3) as int)
      

  5.   

    order by  cast( substring(a,2,charindex('-',a)-1) as int)
      

  6.   

    汗了,这些SQL语句执行都报错的啊,说SUBSTRING函数传递了无效的LENGTH参数。有些朋友直接复制我的的错误句子让人更汗了。
    求教高手啊……
      

  7.   

    select a from A where a not in (select a from B )
    order by 
    case when len(a) < 3 then 0
         when charindex('-',a) < 3 then 0
         when patindex('%^[0-9]%',substing(a,2,charindex('-',a)-2))>0 then 0
         else substing(a,2,charindex('-',a)-2) end
      

  8.   

    select a from A where a not in (select a from B )
    order by 
    case when len(a) < 3 then 0
         when charindex('-',a) < 3 then 0
         when patindex('%^[0-9]%',substing(a,2,charindex('-',a)-2))>0 then 0
         else cacst(substing(a,2,charindex('-',a)-2) as int) end