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.
| 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 datetimeset @SearchDate = '20090325'select *from MyTablewhere -- 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=64762CODO ERGO SUM |
 |
|
|
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' |
 |
|
|
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 resultRefer MVJ's replyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|