sql server 视图 的一个例子

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

                    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

而后 发现 结果 不同了。3d

 

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

因此 只能写 成 :    select * from  view_UserRecord where RecordID=41 or RecordID is nullblog

相关文章
相关标签/搜索