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 2005 Forums
 Transact-SQL (2005)
 how to query date in stored procedure?

Author  Topic 

jrahma
Starting Member

16 Posts

Posted - 2007-08-25 : 13:00:31
Hi,

I want to know how can i query from sql server date field without the time?
i mean if i have the following dates:

8/22/2007 12:00:00 AM
8/22/2007 12:23:00 AM
8/22/2007 04:15:00 PM


and i want to SELECt all the 8/22/2007 dates..


how can i creates such stored procedure?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-25 : 16:03:01
CREATE PROC dbo.uspTest
(
@theDate AS DATETIME
)
AS

SELECT *
FROM Table1
WHERE Col1 >= DATEADD(DAY, DATEDIFF(DAY, 0, @theDate), 0)
AND Col1 < DATEADD(DAY, DATEDIFF(DAY, 0, @theDate), 1)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-27 : 02:17:57
More on querying dates
http://sql-server-performance.com/fk_datetime.asp

Madhivanan

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

- Advertisement -