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/*结果 正确 */
(
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/*结果
正确
*/