sql2000 判断单双问题谢谢
表1id  数据
1    12
2     5
3     3
4     4 
..
得表2
id  数据 单双
1    12   双
2     5   单
3     3   单
4     4   双
..

解决方案 »

  1.   


    declare @表1 table (id int,数据 int)
    insert into @表1
    select 1,12 union all
    select 2,5 union all
    select 3,3 union all
    select 4,4select *,单双=case 数据%2 when 1 then '单' else '双' end  from @表1
    /*
    id          数据          单双
    ----------- ----------- ----
    1           12          双
    2           5           单
    3           3           单
    4           4           双
    */
      

  2.   


    SELECT id, 数据, 单双 = CASE 数据 
        WHEN (数据 % 2) = 0 THEN '偶'
        ELSE '单'
        END
    FROM 表名
      

  3.   

    参考http://msdn.microsoft.com/zh-cn/library/ms190279.aspx
      

  4.   

    select *,单双=case when 数据%2=0 then  '双'  else '单'end  from 表1