0

I am trying to select the price between two date (star date and end date). In my database i have fixed price like this:

2013-05-01 to 2013-05-31  price: 300
2013-06-01 to 2013-06-30  price: 200
2013-07-01 to 2013-07-01  price: 250

I user selects any date between these 3 i am able to generate result by doing

sdate>='2013-05-01' 
AND edate <='2013-05-31'`. 

But if a user selects date 2013-05-28 to 2013-06-03 then it should two days price (300) for may month and 3 days price (200) from the month june. How can i achieve this?

Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
user2316844
  • 37
  • 1
  • 3
  • 8
  • Your original WHERE statement should still work, maybe theres something more in the query we aren't shown? Such as TOP 1? – cgatian May 03 '13 at 11:49

3 Answers3

3

try this

 select price from tablename where sdate >= '2013-05-01' and edate <= '2013-05-31'
thumber nirmal
  • 1,639
  • 3
  • 16
  • 27
1

if user enter date for two different months then your select query will return two prices. assume select price from tb_demo where sdate>='2013-06-01' and edate<='2013-07-31' this will return two prices which is stored into resultset.

After that by using while loop you can easy print those price.If u want to print month name also then use array and print that name.

Jayant Jadhav
  • 318
  • 4
  • 12
0

Please Before positing Use search...

SQL query to select dates between two dates

Community
  • 1
  • 1
Rajesh R
  • 125
  • 7