Print Page | Close Window

SQL Server date issue

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3144
Printed Date: 29 March 2026 at 12:52pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: SQL Server date issue
Posted By: joshb
Subject: SQL Server date issue
Date Posted: 30 May 2003 at 10:09am

I am sure this type of question has been asked before but I searched and could not find it. I am migrating from MS Access to MSServer. Here goes:

I have a table holding company policy document info from 2002 and 2003. Well on one of my pages I have a count of how many documents for each year there are, here is my MS Access query:

strSQL = "SELECT Count(tblBulletins.Access_ID) as Bulletins_2002_Count FROM tblBulletins WHERE Approved = True And Deleted = False AND tblBulletins.DateIssued BETWEEN #1/1/2002# AND #12/31/2002#"

Well when I tried making a Stored Proc out of it changing the True to 1 and False to 0 everything is fine until I get to the date surrounded by #'s.

How can I select a date range in SQL I guess is my question, I tried just putting '1/1/2002' AND '12'31'2002' but no dice. It returned incorrect counts.

Can someone please help.

Joshua

 



-------------
I'm a wannabe programmer that knows how to do nothing but create invalid procedure arguments.
http://www.soopportal.com">



Replies:
Posted By: michael
Date Posted: 30 May 2003 at 10:52am
Using:
strSQL = "SELECT Count(tblBulletins.Access_ID) as Bulletins_2002_Count FROM tblBulletins WHERE Approved = 1 And Deleted = 0 AND tblBulletins.DateIssued BETWEEN '1/1/2002' AND '12/31/2002'
is correct syntax thus I suggest doing a count(*).
If that returns an incorrect number I guess your data itself has a problem.


-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: joshb
Date Posted: 30 May 2003 at 11:48am

Thanks a bunch, it works now.



-------------
I'm a wannabe programmer that knows how to do nothing but create invalid procedure arguments.
http://www.soopportal.com">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net