Link to home
Start Free TrialLog in
Avatar of jazjef
jazjef

asked on

How do I return records from a date range with SQL syntax?

I have an SQL table of records from 2006-2007 and I want to select a range of records based upon start and stop dates entered into text boxes.

I'm using Visual Web Developer; SQL Express; Express Management Studio; VB backcoding

Here's my statement:

SELECT [ID], [BILLNUMBER], [CHARGEDATE], [LNAME], [FNAME] FROM [TABLETracking] WHERE (([CHARGEDATE] IS NOT NULL) AND ([CHARGEDATE] >= @CHARGEDATE) AND ([CHARGEDATE] <= @CHARGEDATE2) AND ([7CAT] = @7CAT))


So, the @CHARGEDATE and @CHARGEDATE2 values are coming from textbox dates that are entered. @7CAT is a value from a user-select dropdown list.

However, a start and stop date such as 01/01/2007 to 12/31/2007 will also return records from the year 2006 (arrrghhhh!...frustrating). How can I make this work? I know there is a BETWEEN statement that can be used, but I am unable to get anything to work..... maybe my parentheses are not structured correctly. Thanks for any assistance.
Avatar of cforant
cforant
Flag of United States of America image

SELECT column_name FROM table_name
WHERE column_name
BETWEEN value1 AND value2
ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jazjef
jazjef

ASKER

asvforce:

thanks for the reply... your statement works fine, but I still get records from 2006 when I use it.
What is the column type of CHARGEDATE column?
Avatar of jazjef

ASKER

ASVFORCE:

column type was char(10)

this was causing the problem.... when I converted to datetime your solution works.... and so does my own original solution prior to asking the question.... thanks.

I have another problem though.... I will post a question on it momentarily. It's related to this datetime thing...
Good catch!!! Glad to hear that you have solved this now.