Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
tow column

Price and Order Date

I would like to write mssql query for selecting highest price from Price Column during last two weeks of Order Date column.
Updated 12-Dec-12 5:26am
Herman<T>.Instance 12-Dec-12 11:26am    
you tag C# but you mean SQL

SELECT MAX(Price) FROM myTable WHERE DateDiff(ww, OrderDate, getDate()) < 2

More info about the use of DateDiff can be found here[^].
Share this answer
SELECT MAX(Price) FROM myTable WHERE OrderDate BETWEEN '2012-12-12' AND '2012-11-28'
Share this answer
Herman<T>.Instance 12-Dec-12 11:25am    
these are fixed dates while other more flexible functions are available im MSSql
OriginalGriff 12-Dec-12 11:35am    
I agree, but I am assuming the OP is bright enough to be able to pass the appropriate dates through as parameters from whatever presentation layer language he is using. Bear in mind that his definition of "last two weeks" might be "a week last Monday", or a fortnight before last Monday", not "exactly two weeks back from today"
Killzone DeathMan 12-Dec-12 11:27am    
I love that OriginalGriff, always the best answer!
I think we must speak in Private!
Herman<T>.Instance 12-Dec-12 11:31am    
I also appreciate is correct way of answering questions on this forum, but sometimes (mostly SQl) I can give some other solutions
Killzone DeathMan 13-Dec-12 4:33am    
That's how it rolls :P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900