Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 26th, 2005, 04:56 PM
slicket2000 slicket2000 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 6 slicket2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 4 m 55 sec
Reputation Power: 0
Best way to search for values in a range of dates

I know there are a millions ways to do this. I think I am doing this the most inefficiennt way.

What is the best T-SQL Script to return a set of values within a range of dates. The lower and upper dates are provided by the user.

For example the input to the T-SQL stored proc would be 2 dates (i.e. 10/16/2004 and 2/18/2005) chosen by the user. The script will return all entries that were created on those dates (assuming the table in SQL server has a timedate stamp that was filled automtically when each row in the table was populated)

i.e. tbl_sample has columns
-----------------------------------
name description time-date stamp
-----------------------------------

Thanks,

Any help would be good.

Reply With Quote
  #2  
Old July 26th, 2005, 05:22 PM
kcconnor's Avatar
kcconnor kcconnor is offline
Evil Republican...
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Probably running over your cat right now...
Posts: 250 kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 35 m 23 sec
Reputation Power: 37
Code:
declare @startdate datetime
declare @enddate datetime

select * from tablename 
where timefield 
between @startdate and @enddate


That should do the trick...

Reply With Quote
  #3  
Old July 27th, 2005, 09:43 AM
slicket2000 slicket2000 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 6 slicket2000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 4 m 55 sec
Reputation Power: 0
Thanks. That's the way I am using right now
and its proably good enough!

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Best way to search for values in a range of dates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT