Home > Back-end >  TERADATA Query for entire month
TERADATA Query for entire month

Time:09-20

I wanted to know if there was a way to extract data from a date column pertaining to an entire month.

SEL * FROM DB.TBLNAME TABLE WHERE TABLE.DATE_ BETWEEN DATE '01-02-2022' AND DATE ' 28-02-2022'

So in the above query(wrote it here as an example so hope i didnt make any typo mistake) im searching for all dates from the 1st to the 28th of february but wanted to know if there was a more elegant method as to select a month match eg. 02-2022.

I hope my question was detailed enough.

Thanks in advance,

CodePudding user response:

For this you could do something like this to make it easier to develop and change as you would need it

SELECT
     *
FROM DB.TBLNAME TABLE
WHERE 1=1
     AND MONTH(TABLE.DATE) = 2
     AND YEAR(TABLE.DATE) = 2022

This is how I would normally do it as you would then be able to write a python script to go with it or a param to dynamically pull the data you need for the month/year

  • Related