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
 General SQL Server Forums
 New to SQL Server Programming
 daterange select problem

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-10-03 : 02:28:49
i need to select daterange between '01 apr 2008' and '30 jun 2008'
by this all 3 record should come.can any one help how to solve

Table:Test
item amt period_from period_to
'AA' 11.00 20080401 30042008
'fd' 12.00 20080501 31052008
'ff' 450.00 20080601 30062008



Tried so far,
select * from test
where ('01 apr 2008' between period_from and period_to)
and
('01 jun 2008' between period_from and period_to)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 02:33:55
SELECT *
FROm table
WHERE period_from >=@start
AND period_from <=@end
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-03 : 02:53:38
change the variables

SELECT *
FROm table
WHERE period_from <= @end
AND period_to >= @Start




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 03:11:02
quote:
Originally posted by Peso

change the variables

SELECT *
FROm table
WHERE period_from <= @end
AND period_to >= @Start




E 12°55'05.63"
N 56°04'39.26"



copy paste error
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-10-03 : 05:34:53
Txs peso and visakh16

quote:
Originally posted by visakh16

quote:
Originally posted by Peso

change the variables

SELECT *
FROm table
WHERE period_from <= @end
AND period_to >= @Start




E 12°55'05.63"
N 56°04'39.26"



copy paste error

Go to Top of Page
   

- Advertisement -