| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | 

您现在的位置: 中国X黑客小组 >> 技术文章 >> 编程技术 >> 网络编程 >> 文章正文 用户登录 新用户注册
  SQL Server语句做数值大小比较的实现          【字体:
SQL Server语句做数值大小比较的实现
作者:IT专家网    文章来源:CnXHacker.Net    点击数:    更新时间:2006-10-27    
问: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 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 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    活地运用SQL Injection做数据
    数据库安全应用 使用MySQL的
    MSSQL数据库SA权限入侵的感悟
    XSS跨站脚本及SQL注入漏洞技
    开源MySQL停止提供企业版源代
    打造SQL Server2000的安全策
    堵死网站被SQL注入的隐患
    wtoolsa.exe - wtoolsa - 进
    microsoft.visualstudio.too
    microsoft.visualstudio.tex
      网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!)
    Powered by ICE RIVER - STUDIO
    » CnXHacker.CoM   © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved.