简体   繁体   中英

SQL Server: How to add a specific date to date range query

I have a query that currently searches for records that have a payment date year within the current year.

I need to modify the query so that it searches records starting from November 15th of the previous year, in this case 2019 to anything within the current year 2020.

How can I add this date range?

This is my current query:

SELECT
    RECORD_ID 
,   RECORD_TYPE 
,   PERMIT_TYPE
,   RECORD_STATUS
,   PURCHASE_DATE
,   PURCHASE_TIME
,   PERMIT_YEAR
,   CONTACT_ADDRESS
,   CONTACT_NAME
FROM  
    PERMIT_VIEW PV
INNER JOIN PERMIT BP
    ON PV.RECORD_ID = BP.RECORD_ID
INNER JOIN PAYMENT P
    ON BP.SERV_PROV_CODE = P.SERV_PROV_CODE     
WHERE 
    RECORD_TYPE IN ('Annual')
    AND YEAR(PURCHASED_DATE) = YEAR(GETDATE())  - This is the part I need to change.
    AND PV.RECORD_ID NOT LIKE 'DLY%'
    AND RECORD_STATUS NOT IN ('Void')

Thank you for your help,

Erasmo

You can use the condition:

purchased_date >= datefromparts(year(getdate()) - 1, 11, 15)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM