|
|
| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | | ||||
|
|
||||||||
|
||||||||
|
|||||
| SQL Server语句做数值大小比较的实现 | |||||
作者:IT专家网 文章来源:CnXHacker.Net 点击数: 更新时间:2006-10-27 ![]() |
|||||
|
我有①、②二张表: ①表有一个字段。通过条件查询出来其中一个字段的返回值。 ②表有二个字段。通过条件查询出来其中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 null ) insert into t1 select '1', 10 union all select '2', 20 insert into t2 select '1', 3, 5 union all select '2', 12, 9 declare @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 '正确' end select @Res drop table t1 drop table t2 /*结果 正确 */ |
|||||
| 文章录入:IceRiver 责任编辑:IceRiver | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!) |
| 关于我们 - 版权声明 - 帮助(?) - 广告服务 - 联系我们 - 友情链接 - 用户注册 - | Powered by ICE RIVER - STUDIO |
| » CnXHacker.CoM | © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved. |