Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2005, 01:28 AM
SoC SoC is offline
Authorized User
 
Join Date: Jul 2004
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datetime, wildcards etc

Hi,

I have an ASP page that enables the user to search an SQL database.

I have a form that lets the user select a number of different criteria to search on. One of the form elements is a Select box that contains the 12 months, their values being 1-12 respectively.

I can search with this and successfully return only the records containing the selected month. However, I would like to be able to search on all months. I added another option "All", with a null value, but this does not work.

My SQL statement looks something like ... SELECT * FROM myTable WHERE Month(myDateField) = 'myDateVariable'

I have tried using WHERE Month(myDateField) LIKE '%myDateVariable%' but when searching on January (1) and February(2), other months that contain these digits are also returned (Oct, Nov, Dec).

Is it possible to set the values of my select options to text 'Jan', 'Feb', etc? Or is there another way?

s

 
Old July 19th, 2005, 06:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What type is the MyDateField?
Try using DATEPART() instead of MONTH() there.

_________________________
- Vijay G
Strive for Perfection
 
Old July 19th, 2005, 07:42 PM
SoC SoC is offline
Authorized User
 
Join Date: Jul 2004
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi happygv,

The type is datetime. I tried using DATEPART(mm, myDateField), but still no luck.

I also tried DATEPARAT(m, myDateField) and DATEPART(month, myDateField). I have also tried changing the format of the field to Medium, Short etc.

This is part of my select code:

<select name="selectMonth" id="selectMonth">
<option value="">All</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select>

I have tried various combinations of values and different SQL statements that include either LIKE %selectMonthVariable% or = selectMonthVariable.

Using = I can get it to work, but not for the 'All' select option. I have also tried setting the option values to "01" for January and "02" for Feb, but this doesn't work either. I thought you might be able to set the values to 'Jan', 'Feb' etc, but this doesn't work.

This is starting to drive me nuts! There has got to be an easy way to do this.

Thanks
s

 
Old July 19th, 2005, 07:59 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Maybe try:
1..Change your All value to <option value="0">All Months</option>
2..Now when the form gets submitted conditionaly create the sql, EG:

sql = "SELECT * FROM myTable WHERE "
if request.form("monthSelections") = 0 then
   sql = sql & " Month(myDateField)<= 12;"
else
   sql = sql & " Month(myDateField)= 'myDateVariable';"
end if

Wind is your friend
Matt
 
Old July 19th, 2005, 08:09 PM
SoC SoC is offline
Authorized User
 
Join Date: Jul 2004
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Matt, I thought I might end up having to do something like that.

It just seems strange that I can't use text values 'Jan', 'Feb', 'Mar' etc. I have seen various examples that show you can query datetime fields in this manner.

 
Old July 19th, 2005, 08:35 PM
SoC SoC is offline
Authorized User
 
Join Date: Jul 2004
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, got it to work using conditional statement, so thanks again Matt.

 
Old July 19th, 2005, 08:53 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

no worries

;;;It just seems strange that I can't use text values 'Jan', 'Feb', 'Mar' etc
You can but Integers are generaly faster than strings, use strings if you can not use integers.

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable the wildcards(% and _) kasipandian Oracle 1 February 4th, 2008 12:32 AM
ObjectDataSource and Wildcards pipelineconsulting ASP.NET 2.0 Professional 1 October 19th, 2006 09:08 PM
Using wildcards in subquery hman SQL Language 2 April 11th, 2005 06:18 AM
Help using wildcards in query hman SQL Language 2 April 6th, 2005 03:40 AM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.