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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help on between operator

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
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-15 : 03:42:38
Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Yula
Starting Member

4 Posts

Posted - 2007-06-15 : 04:15:12
Sample data:

day year description Id
--- ---- ----------- --
12 2006 test1 001
20 2007 test2 002
35 2006 test3 003
55 2007 test4 004
56 2005 test5 005
05 2007 test6 006


i 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.
Go to Top of Page

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 @t
select 12, 2006, 'test1', 001 union all
select 20, 2007, 'test2', 002 union all
select 35, 2006, 'test3', 003 union all
select 55, 2007, 'test4', 004 union all
select 56, 2005, 'test5', 005 union all
select 05, 2007, 'test6', 006

Select *
from @t
where (day between 05 and 12) and
year (between 2006 and 2007)

--------------------------------------------------
S.Ahamed
Go to Top of Page

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]

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -