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 2008 Forums
 Transact-SQL (2008)
 checking on a date range

Author  Topic 

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-06-29 : 03:47:54
[code]
AND

(
(
(begindate BETWEEN cast(@datefrom as datetime) AND cast(@datetill as datetime))
OR
(enddateBETWEEN cast(@datefrom as datetime) AND cast(@datetill as datetime))
)
OR
(
(begindate < cast(@datefrom as datetime))
AND
(einddatum BETWEEN cast(@datefrom as datetime) AND cast(@datetill as datetime))
)
OR
(
(begindate BETWEEN cast(@datefrom as datetime) AND cast(@datetill as datetime))
AND
(enddate> cast(@datetill as datetime))
)
OR
(
(begindate< cast(@datefrom as datetime))
AND
(enddate> cast(@datetill as datetime))
)
)[/code]

i feel like this is far from optimal, and since this is pretty crucial to my program i post it here to get a second opinion :)

so i check on a daterange i submit with 2 parameters, in the db each row contains a begin and enddate which u can see in the qry

thx alot in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-29 : 05:43:54
[code]WHERE BeginDate <= @DateTill
AND EndDate >= @DateFrom[/code]



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

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-06-29 : 09:16:44
omfg is this true ?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-29 : 09:33:30
Yes.



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

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-06-29 : 10:50:43
quote:
Originally posted by Peso

WHERE   BeginDate <= @DateTill
AND EndDate >= @DateFrom




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




As long as @DateFrom <= @DateTill, of course.



CODO ERGO SUM
Go to Top of Page

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-06-30 : 08:28:47
this really must be some of the most stupidest queries ever submitted here ... :$
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-30 : 08:44:43
No, it isn't. Trust me on this one...



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

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-07-01 : 02:58:01
feeling a little bit better now :)

i was thinkin of this in bed.... and always its the same.... *

thinking* THEY ARENT RIGHT AT SQLTEAM.... *ow wait* yes they are :(
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-07-01 : 15:08:56
Solutions sometimes turn out to be shockingly simple.





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -