SQL Code如何获取当前年份和月份的数据?

时间:2017-10-09 06:41:15

标签: sql sql-server tsql

我不知道如何选择九月份

SELECT SUM(CAST(QtyOrdered * Price as money)) 'Total Order Price for September'
FROM tblPurchaseOrderLine
WHERE year (DateNeeded) = year (GETDATE())

3 个答案:

答案 0 :(得分:2)

尝试以下示例查询以获取当前年份和月份的数据。

SELECT * from <tablename>
WHERE year = YEAR(GETDATE())
and month = MONTH(GETDATE());

答案 1 :(得分:0)

添加此谓词结尾的位置

AND month (DateNeeded)  =9

答案 2 :(得分:0)

将此添加到最后

func setupAgreement() {

        let customType1 = ActiveType.custom(pattern: "\\sterms of service\\b") //Looks for "are"
        let customType2 = ActiveType.custom(pattern: "\\sprivacy policy\\b") //Looks for "it"
        let customType3 = ActiveType.custom(pattern: "\\scookie use\\b") //Looks for "supports"

        userAgreementLabel.enabledTypes.append(customType1)
        userAgreementLabel.enabledTypes.append(customType2)
        userAgreementLabel.enabledTypes.append(customType3)

        userAgreementLabel.customize { (label) in

            label.text = "UserAgreement".localized
            label.numberOfLines = 0
            label.lineSpacing = 4
            label.textColor = UIColor(red: 0 / 255, green: 0 / 255, blue: 0 / 255, alpha: 1)

            //Custom types
            label.customColor[customType1] = Constant.AppColor.blueColor
            label.customSelectedColor[customType1] = Constant.AppColor.blueColor
            label.customColor[customType2] = Constant.AppColor.blueColor
            label.customSelectedColor[customType2] = Constant.AppColor.blueColor
            label.customColor[customType3] = Constant.AppColor.blueColor
            label.customSelectedColor[customType3] = Constant.AppColor.blueColor

            label.configureLinkAttribute = { (type, attributes, isSelected) in
                var atts = attributes
                switch type {
                case customType1:
                    atts[NSFontAttributeName] = UIFont(name: self.userAgreementLabel.font.fontName, size: 15.0)
                case customType2:
                    atts[NSFontAttributeName] = UIFont(name: self.userAgreementLabel.font.fontName, size: 15.0)
                case customType3:
                    atts[NSFontAttributeName] = UIFont(name: self.userAgreementLabel.font.fontName, size: 15.0)
                default: ()
                }

                return atts
            }

            label.handleCustomTap(for: customType1, handler: { (value) in
                self.load(cms: .terms)
            })
            label.handleCustomTap(for: customType2, handler: { (value) in
                 self.load(cms: .privacy)
            })
            label.handleCustomTap(for: customType3, handler: { (value) in
                self.load(cms: .cookie)
            })

        }
    }

    //  func navigateToWebView() {
    //      let controller = self.storyboard?.instantiateViewController(withIdentifier: Constant.StoryBoardIdentifier.webViewController)
    //      self.present(controller!, animated: true, completion: nil)
    //      
    //  }
    func load(cms: CMS) -> Void {
        let cmsController: CMSViewController = UIStoryboard(storyboard: .setting).initVC()
        cmsController.cms = cms
        show(cmsController, sender: cmsController.classForCoder)
    }