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
 Search By Date

Author  Topic 

unc0ntr0l
Starting Member

1 Post

Posted - 2009-03-25 : 18:26:55
So im pretty new to SQL and ive been working on a small project just to test out some Stored Procedures but this is a bit harder than I thought. What im trying to do is search for a customer (in an SQL database) by date (in VB08). The SELECT statement I know how to use the select statement to select the data, but I am stuck on how to ask it to retrieve it from a date choosen. For ex:
If I select 1/2/2009 and want it to retrieve customers who purchased products on that date and have it show on a Data Grid View. Just want helping start, I like being able to challenge myself. Any help is appreciated

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-03-25 : 23:40:18
[code]
declare @SearchDate datetime
set @SearchDate = '20090325'

select
*
from
MyTable
where
-- Sale datetime is greater then or equal to @SearchDate
SaleDateTime >= @SearchDate and
-- Sale datetime is before the day after @SearchDate
SaleDateTime < dateadd(day,1,@SearchDate)

[/code]


Other info about working with Date/Time in SQL Server and links to many scripts for working with SQL Server datetime:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762

CODO ERGO SUM
Go to Top of Page

m_z_iqbal
Starting Member

28 Posts

Posted - 2009-03-26 : 00:56:22
SELECT * FROM youtable WHERE datefield >='date in string' AND datefield <= 'date in string'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-26 : 02:35:06
quote:
Originally posted by m_z_iqbal

SELECT * FROM youtable WHERE datefield >='date in string' AND datefield <= 'date in string'


It would give you different result
Refer MVJ's reply

Madhivanan

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

- Advertisement -