Click here to Skip to main content
15,944,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to write mssql query for selecting highest price from Price Column during two weeks starting from today.

Thanks
Posted

XML
Hi ttds,

Your Query is not so clear .
/*
Assuming Table name as tblPrice and Date Column to be colDate
*/

1) Incase if you want output as maximum price within 2 weeks

Select max(Price) from tblPrice
where colDate between Dateadd (dd,-14,getdate()) and getdate();

2) In case you want datewise max price as output

Select max(Price),colDate from tblPrice
where colDate between Dateadd (dd,-14,getdate()) and getdate()
group by colDate
 
Share this answer
 
v2
Something like:
SQL
SELECT MAX(Price) FROM MyTable WHERE MyDate > DATE_SUB(CURDATE(), INTERVAL 2 WEEK)
 
Share this answer
 
Hi,

SELECT MAX(Price) FROM Price_Table WHERE PRICE_DT Between DATEADD(DAY,-14,SYSDATETIME()) and SYSDATETIME()
 
Share this answer
 
SQL
Select max(Price) from tblPrice
where colDate > Dateadd(wk,-2,getdate())
 
Share this answer
 

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