I have a form in asp with two text boxes. If user enters a value in it and submit, it displays data from MS access query for the selected dates by user. If users just leave both text boxes blanks, I want to display complete output from the database.
This is my sample query in access :
select column_date, field1, field2, sum(field3) from table1
where field1 like '*xyz' and
column_date between [@startdate] and [@enddate]
group by column_date, field1, field2
My asp codes are similar to below :
objCmd.CommandText = "Query"
objCmd.CommandType = adCmdStoredProc
Set objParam = objCmd.CreateParameter("@startdate" , adInteger, adParamInput, 0, 0)
objCmd.Parameters.Append objParam
Set objParam = objCmd.CreateParameter("@enddate" , adInteger, adParamInput, 0, 0)
objCmd.Parameters.Append objParam
if request.form ("startdate") = "" Then
objCmd.Parameters ("@startdate") = 1
Else
objCmd.Parameters("@startdate") = request.form("startdate")
objCmd.Parameters("@enddate") = request.form("enddate")
End if
if request.form ("enddate") = "" Then
objCmd.Parameters ("@enddate") = 31
Else
objCmd.Parameters("@startdate") = request.form("startdate")
objCmd.Parameters("@enddate") = request.form("enddate")
End if
................
Please note my startdate and enddates are text datatype with just numbers e.g. 1, 2, 3, 4, 5 ( 1 means 1st July 2012, 2 means 2nd July 2012)
I have two text boxes name “startdate” and “enddate”. When user enters dates in the boxes, it returns data between the two dates from the query. If user leaves blank, it shows error.
But I want to make sure if user leave both text boxes blank, it returns all values from the query. If user input a single value in any of the two text boxes, it should return data only for that date.
I’m not sure how can I achieve it.
You say
“Please note my startdate and enddates are text datatype with just numbers e.g. 1, 2, 3, 4, 5. (1 means 1st July 2012, 2 means 2nd July 2012 and so on).”
Which suggests that the date cannot be less than 1 or greater than 31. Can you do some pre-processing on your dates?
If the first date is null and the second date is null, then the “dates” should be 1 and 31.
If either of the two dates is null but the other is not null, the “dates” should be equal to each other.
Pseudo code:
This would give you :
And, say