SQLTeam.com | Weblogs | Forums

How to make past 6 month date dymanic

Hi,
I appreciate any help with this!
I have this query that takes past 6 month, I want to make this dynamic because I'm using this in Powerbi and so each month I refresh the data in powerbi, it bring in the current past 6 month.

SELECT DISTINCT AGENT_ID
FROM DB2PROD.BONUS_PAYMENT
WHERE BONUS_TYPE = 'R'
AND NEW_BIZ_YR = '2022'
AND NEW_BIZ_MO >= '3'

Welcome

New_biz_yr and _mo are varchar date type?

I don't think so. NEW_BIZ_YR is a Year Column and
AND NEW_BIZ_MO is a Month Column

There are no such data types in sql server. Month year.

Since you are using quote marks, we will assume varchar

I guess it is, Maybe I'm confused..
btw this is from WINSQL server

This is a Microsoft sql server forum. but if you go to this site there is syntax that might help you achieve that

https://www.synametrics.com/WinSQLUsersGuide/index.htm?context=10

CURDATE() Returns the current date.
MONTH(date_exp) Returns the month based on the month field in date_exp as an integer value in the range of 1 – 12.

YEAR(date_exp)

Returns the year based on the year field in date_exp as an integer value. The range is data source – dependent.

TIMESTAMPDIFF(interval, timestamp_exp1, timestamp_exp2)

So using a combination of these functions you could figure it out. Might be better off posting on a winsql forum?

I know, but there's no active WinSQL Forum out there.