用CASE,Select Case When 返回结果1>返回结果2 Then N'错误' Else N'正常' End最好能贴出数据,这样可以帮你写完整的SQL语句。

解决方案 »

  1.   

    create table t1
    (
      idd varchar(10) not null,
      value int not null
    )create table t2
    (
      idd varchar(10) not null,
      value1 int not null,
      value2 int not null
    )insert into t1
    select '1', 10
    union all
    select '2', 20insert into t2
    select '1', 3, 5
    union all
    select '2', 12, 9declare @Res varchar(10)
    select @Res = case  when ((select t1.value from t1 where idd='2')  > (select value=t2.value1+t2.value2 from t2 where idd='2') )
                     then '错误' else '正确' endselect @Resdrop table t1
    drop table t2/*结果
    正确
    */