Monday, February 20, 2012

Max with Datepart

I am wanting to set any given @.Date parameter to the most current recorded Monday in a table (tblMarketPricing). Would this work:

@.Date = Max(Datepart(dw,MktDate) IN 2

I am unsure if you can use Max with the Datepart function.

***If this is not allowed, can anyone suggest anything different that I might try?

To get what you are asking for you need:

Select @.date = Max(MktDate) from tblMarketPricing where DatePart(dw, MktDate) = 2

assuming that 2 corresponds to Monday on your system.

You could consider using the DateName() function in place of DatePart().

Since it will otherwise be forthcoming, I will suggest that a Calendar table could also be used to provide these sorts of answers.

|||That worked! Thank you.

No comments:

Post a Comment