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
 select*from tbl where d like '2008.03.25%' ???

Author  Topic 

landau66
Yak Posting Veteran

61 Posts

Posted - 2008-08-26 : 15:57:33
Hi everyone!


I tried the following:
select*from tbl where d like '2008.03.25%'

I want to have all entries from this day - why is it not working??

thank u very much in advance and greetings from vienna

landau

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-26 : 16:01:21
What data type is column d?

SELECT * FROM tbl WHERE d >= '2008-03-25' AND d < '2008-03-26'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-08-26 : 16:11:23
SELECT * FROM tbl WHERE Datediff(Day, d, '2008-03-25') = 0


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2008-08-26 : 16:23:17
Hi!

Thanks for the answer. The datatype is datetime!

But what would u do in this case:

SELECT * FROM tbl WHERE d like '2008-03-25 09:%'
?

with this i want to get the entries from every day from 9 till under 10

Thanks a lot

landau
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-26 : 16:27:54
SELECT * FROM tbl WHERE d >= '2008-03-25 09:00' AND d < '2008-03-25 10:00'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2008-08-26 : 16:30:51
sorry to bother u again.

i want the entries from ALL DAYS (more than one) between 9 and 10

thanks, landau
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-26 : 17:02:04
SELECT * FROM tbl WHERE datePart(HOUR, d) = 9

-- I don't have access to a database server to check my syntax but think it should work.

-------------
Charlie
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-26 : 17:05:36
It's going to have to scan the table/index, so be prepared to wait a bit for a large table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-27 : 02:27:21
If the column has index, to make use of it, use

select columns from table
where
dateadd(hour,datediff(hour,0,loggedin),0)>=dateadd(hour,9,dateadd(day,datediff(day,0,loggedin),0)) and
dateadd(hour,datediff(hour,0,loggedin),0)<dateadd(hour,10,dateadd(day,datediff(day,0,loggedin),0))




Madhivanan

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

- Advertisement -