create table T1
(名称 varchar(20),   数量1 int,   数量2 int,   差额 int,    标致 varchar(10),  时间 datetime,)
insert into t1(名称,数量1,数量2)
select 'A'   ,     10   ,    5
union all select 'B'    ,    20   ,    21
union all select 'C'    ,    100    ,  89
union all select 'D'  ,      500    ,  702
select 名称  ,  数量1 ,   数量2 ,   差额= abs(数量1-  数量2), 标致 =case  when 
 (数量1-数量2)>0 then ' 大' when (数量1-数量2)<0 then '小' else '相等'end ,时间=getdate() from t1

解决方案 »

  1.   

    declare @t table(名称 varchar(20), 数量1 int,数量2 int)
    insert into @t
    select 'A'   ,     10   ,    5 union all 
    select 'B'    ,    20   ,    21 union all 
    select 'C'    ,    100    ,  89 union all 
    select 'D'  ,      500    ,  702select 名称,数量1,数量2,   
           差额= abs(数量1-数量2), 
           标致 =case  when (数量1-数量2)>0 then '大' when (数量1-数量2)<0 then '小' else '相等'end ,
           时间=cast(getdate() as smalldatetime)
    from @t(所影响的行数为 4 行)名称                   数量1         数量2         差额          标致   时间                                                     
    -------------------- ----------- ----------- ----------- ---- ------------------------------------------------------ 
    A                    10          5           5           大    2005-12-11 09:17:00
    B                    20          21          1           小    2005-12-11 09:17:00
    C                    100         89          11          大    2005-12-11 09:17:00
    D                    500         702         202         小    2005-12-11 09:17:00(所影响的行数为 4 行)