All
I know this one has probably been discussed to death before now, however if only once more...
I am trying to get this coding right, so it will enable me to retrieve all transactions of the previous month. It is the combination of DatePart and DateAdd that has me confused. The following is what I have (this is quizzing a Sybase DB)
WHERE (DatePart(month,dp_history.effective_dt) = DATEPART(mm, GETDATE())) AND (DatePart(year,dp_history.effective_dt) = DATEPART(yy, GETDATE()))
Secondly, I wanted to be able to adjust the code to tak into account if the current month is January. If this was the case, I would then need to not only look for month -1, but also year -1. This one is a nice to have, but I thought I might as well ask at the same time.
Cheers
Gezza
I know this one has probably been discussed to death before now, however if only once more...
I am trying to get this coding right, so it will enable me to retrieve all transactions of the previous month. It is the combination of DatePart and DateAdd that has me confused. The following is what I have (this is quizzing a Sybase DB)
WHERE (DatePart(month,dp_history.effective_dt) = DATEPART(mm, GETDATE())) AND (DatePart(year,dp_history.effective_dt) = DATEPART(yy, GETDATE()))
Secondly, I wanted to be able to adjust the code to tak into account if the current month is January. If this was the case, I would then need to not only look for month -1, but also year -1. This one is a nice to have, but I thought I might as well ask at the same time.
Cheers
Gezza