《sqlserver语句做数值大小比较的实现》由会员分享,可在线阅读,更多相关《sqlserver语句做数值大小比较的实现(2页珍藏版)》请在金锄头文库上搜索。
1、SQLServer语句做数值大小比较的实现问:sql server里我有、二张表:表有一个字段。通过条件查询出来其中一个字段的返回值。表有二个字段。通过条件查询出来其中2个字段的返回值,并将其值相加。然后把、表的返回值做数字的大小比较。如果返回表的值大于表的值,则返回“错误”的提示。反之,则报正常。怎么写这个sql语句?答: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 n
2、ull)insert into t1select 1, 10union allselect 2, 20insert into t2select 1, 3, 5union allselect 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 t1drop table t2/*结果正确*/