再sql server2005中。select * from t order by unitID,0;会出错;select * from t order by unitID,case when color is NULL then 0 else  ID end  ; 不会出错, 为什么, 同样 有可能是0啊

解决方案 »

  1.   

    select * from t order by unitID,0
    改为
    select * from t order by unitID,2 就可以了
      

  2.   

    LS:
    我是问 比如 , color字段 为null, 那么 第2条语句会成和第一条一样,为什么不会报错呢?
      

  3.   

    select * from t order by unitID,0; 的 0 是 字段顺序 没有 第 0 个字段,所以报错select * from t order by unitID,case when color is NULL then 0 else  ID end
    的 0 是字符 或者是 数字 在排序的时候,将空值转换为 0处理,所以不会报错。
    个人见解,不知道对不对,如果不对请各位大哥指出 :)