zoukankan      html  css  js  c++  java
  • SQL语句的巧用以前没这么用过


    --SQl 的巧用
    --select 常值 as 列名 from 表名    
    --在查询出的结果里加一个常量字段
    select 'Type' as type from Earn_Money

    --select 方法(参数) as 列名        
    --查询出此方法的值作为列值 类似select @@version
    select sin(90) as Sin值                            

    --Update 表名 set 字段=case when 条件1 then 结果1 else 结果2 end where 条件2
    --更新表符合条件2的记录的某字段,当符合条件1时候此字段为结果1否则为结果2
    Update Oper_PriceBody2
    Set FSellMoney = Case When @YMSL<=3000
                      Then (FOpen/4)*@ZHZSS+(@ZSS*FColor)
                      Else FSellPrice*(@ZCSS+@Temp)*@YSTCS End,
        FMoney = Case When @YMSL<=3000
                      Then (FOpen/4)*@ZHZSS+(@ZSS*FColor)
                      Else FPrice*(@ZCSS+@Temp)*@YSTCS End
    Where FHead = @BillCode And FItem='印刷'           
                                               
    --Update 表1 set 字段1=值1 from 表2 where 条件1 
    --更新表1的字段1为值1 其中值1是表2中的字段,表2是用select语句把值1查询出来 注意:这里把表2当做一个数据集来考虑
    Update Oper_PriceHead
    Set FUnTaxMoney = FSellSum, FBaseMoney = FBaseSum
    From (Select Sum(FSellMoney) As FSellSum, Sum(FMoney) As FBaseSum
          From Oper_PriceBody2
          Where FHead = @BillCode) As T1
    Where FCode = @BillCode                           

    --Insert Into 表1(字段1) select 字段1 from 表2 where 条件1
    --与常用的Insert Into 表1(字段1) values(值1) 不同 注意:其实values(值1)和select(字段1)本质上都是记录集的一条记录
    Insert Into Mate_Relation(FStorageCode, FPlaceCode, FMaterialCode, FValidDate)
          Select Distinct FStorageCode, FPlaceCode, FMaterialCode, FValidDate
          From Mate_BuyRetBody
          Where FHead = @BillCode 
          And (FStorageCode + FPlaceCode + FMaterialCode + Convert(nvarchar,IsNull(FValidDate,'1899-01-01'))) Not In
              (Select FStorageCode + FPlaceCode + FMaterialCode + Convert(nvarchar,IsNull(FValidDate,'1899-01-01')) From Mate_Relation)
     
  • 相关阅读:
    【编程题目】输入一个已经按升序排序过的数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字。
    【编程题目】在一个字符串中找到第一个只出现一次的字符。如输入 abaccdeff,则输出 b。
    Unity3d 开发(七)AssetBundle组织文件夹
    MapReduce 的类型与格式【编写最简单的mapreduce】(1)
    Asterisk[1]
    1181: 念数字
    怎样創建 iOS 展開式 UITableView?
    android自己定义圆盘时钟
    iOS设计模式之NSNotificationCenter 消息中心
    大浪淘沙,JSP终将死去
  • 原文地址:https://www.cnblogs.com/xryyforver/p/1508528.html
Copyright © 2011-2022 走看看