| Author |
Topic |
|
rindharajan
Starting Member
6 Posts |
Posted - 2009-10-13 : 10:08:42
|
| HI i have 2 columns say Month having values (1 to 12)and year having values (2009 - 2015).Now i want to retrieve values between Apr 2009 to Jun 2010...Please help me with the query.Thanks,RindhaRajan |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 10:11:34
|
| Where Date_Field Between Put_Start_Date_here AND Put_End_Date_Here[/fail at query] |
 |
|
|
rindharajan
Starting Member
6 Posts |
Posted - 2009-10-13 : 10:13:12
|
| But date is not a single field...Month and Year are in different field. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-13 : 10:31:43
|
select * from tablewhere convert(varchar(4),yearColumn)+right('00'+convert(varchar(2),ltrim(rtrim(monthColumn))),2)between '200904' and '201506' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-13 : 10:55:12
|
| where dateadd(month,month_col-1,dateadd(year,year_col-1900,0))>=cast('Apr 2009' as datetime) anddateadd(month,month_col-1,dateadd(year,year_col-1900,0))<dateadd(month,1,cast('Jun 2010' as datetime))MadhivananFailing to plan is Planning to fail |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-13 : 11:19:06
|
| I see, I never read the question properly. :) Cheers for the heads up my man, I will make sure to read questions properly in the future[/fail at query] |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-13 : 11:54:14
|
You are right!It is a design problem.But should we not give a solution because it is not a fine solution? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-10-13 : 14:56:26
|
Something like this might work (but it'll probalby scan too because of the OR):SELECT *FROM MyTableWHERE (Month > 3 AND Year = 2009) OR (Month < 7 AND Year = 2010) |
 |
|
|
|