Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Yula
Starting Member
4 Posts |
Posted - 2007-06-15 : 02:50:24
|
Can anybody help me with my problem.. i want to put a between operator on a where clause. and i will use 2 columns(fields) on the between operator. for example:"where day&year BETWEEN fromday&fromyear and toDay&toyear"i need to combine the fields day and year in this where clause..thanks in advance.. |
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-15 : 03:08:33
|
What do yo want to achieve????how u want to combine day and year......why dont u check daya and year separately..Post some sample data...--------------------------------------------------S.Ahamed |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-15 : 03:42:38
|
Post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
|
|
Yula
Starting Member
4 Posts |
Posted - 2007-06-15 : 04:15:12
|
Sample data:day year description Id--- ---- ----------- --12 2006 test1 00120 2007 test2 00235 2006 test3 00355 2007 test4 00456 2005 test5 00505 2007 test6 006i want to get the id and description from day=12 year=2006 to day=05 year=2007. i want to get all rows that fall between those data. |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-15 : 04:59:45
|
declare @t table(day int, year int, description varchar(10), Id int)insert @tselect 12, 2006, 'test1', 001 union allselect 20, 2007, 'test2', 002 union allselect 35, 2006, 'test3', 003 union allselect 55, 2007, 'test4', 004 union allselect 56, 2005, 'test5', 005 union allselect 05, 2007, 'test6', 006Select * from @t where (day between 05 and 12) and year (between 2006 and 2007)--------------------------------------------------S.Ahamed |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-15 : 05:05:21
|
[code]where dateadd(day,day-1,dateadd(year,year-1900,0)) between dateadd(day,12-1,dateadd(year,2006-1900,0)) and dateadd(day,5-1,dateadd(year,2007-1900,0))[/code]MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|