zoukankan      html  css  js  c++  java
  • sql server 视图 的一个例子

    这是一个 有点复杂的查询。我现在 想把他封装 成 视图  其中  B.RecordID= 41 提供给 视图外查询。

                        create view view_UserRecord     
                             as
                             select RecordID,PR.CommonPoint+(PR.OutputValue*0.01) as 'AllPoint',  
                        (PR.OutputValue*0.01) as   'OutputConvertValue', AwardOrPunishment ,
                        PR.CommonPoint ,
                        PR.OutputValue ,
                        PR. RulesID ,
                        RulesName ,
                        RulesOrderNumber ,
                        RulesType ,
                        Unit,  isnull(Cnt,0) as 'Cnt', 
                        isnull(   isnull(Cnt,0)*(B.CommonPoint+(B.OutputValue*0.01)),0) as 'UserAllPoint', 
                          isnull( isnull(Cnt,0)*(B.OutputValue*0.01),0) as 'UserOutputValue'
                 from   dbo.PointRules PR  
                 left join dbo.UserRecordDetails  B on PR.RulesID = B.RulesID 
     select * from  view_UserRecord where RecordID=41

    然后 发现 结果 不一样了。

    这就是 视图 需要注意的地方。他类似   select * from( select * from  tableName )View  这个样子。当里面的结果 集合 有 外连接的的时候 存在 空行的话,再在外面 包一层 ,空行自然 就过滤去了。

    所以 只能写 成 :    select * from  view_UserRecord where RecordID=41 or RecordID is null

  • 相关阅读:
    nginx之location、rewrite配置
    nio buffer
    分布式事务
    彻底剖析RMI底层源码 、手写轻量级RMI框架
    Java RMI详解
    Java提高篇——对象克隆(复制)
    序列化
    分布式通信-tcp/ip 广播
    分布式通信-tcp/ip 单播
    php 图像处理 抠图,生成背景透明png 图片
  • 原文地址:https://www.cnblogs.com/bingguang/p/4665041.html
Copyright © 2011-2022 走看看