ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

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 Dev Shed Forums Sponsor:
  #1  
Old September 8th, 2003, 01:11 AM
FrequeNC FrequeNC is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: OZ
Posts: 7 FrequeNC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
problem using date as filter for record

I am trying to filter a recordset by 3 fields. character name, username, and date.

(some of you may have seen this who have helped me on a few other problems. You guys rock!)

The query runs fine, until I introduce the date element. It says that my syntax is incorrect. I am trying this.

"Select * from fieldname Where valueOne = Request.Querystring("value") and valueTwo = Request.Querystring("value2") and date = date()"

I am sure this is blatantly obvious to some of you, but i can't get it to work. I have put date in a variable:

Dim currentDate
currentDate = date()

and tried "... where date = currentDate"

Any suggestions?

Reply With Quote
  #2  
Old September 8th, 2003, 07:17 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Well you are NOT treating *currentDate* variable like a *variable*

Let me explain myself...

Here you do:
<%
Dim currentDate
currentDate = date()
%>

And then you say:
". . . where date = currentDate"

Well...do you see it?....c'mon look carefully...

Ok I'll tell you

Your variable *currentDate* is inside the double quotes " "

So its like if you were creating a string holding this for a value:
<%
Dim strMyString
strMyString = ". . . where date = currentDate"
'FOR DEBUG ONLY
Response.Write "-->" & strMyString & "<--"
%>

This will output on the screan:'
. . . where date = currentDate

The currentDate is never/not considered as a variable since it is inside the string " "

What you want is to make your variable *act* like a variable otherwise it'll be considered as part of the string. So the end result is:

Dim strSql
strSql = ". . . WHERE date = '" & currentDate &"'"

Now...a couple of things...
First, you would've never posted/ask this question if you'd get into the habit of making a Response.Write of your SQL Query.
You would've seen right away that the error was inside your SQL Query, thus making the appropriate changes...
Now *ALWAYS* Response.Write your SQL query *BEFORE* your execute it. Then look at the result inside your browser...see if there's anu errors, fix them then refresh the page.
Also, you can copy/paste the query into your database and execute it to see if the results are *what you expect* if they are then great if not, then make the necessary adjustments.

Second thing, you also might want to consider, for clarity to use all UPPERCASE for SQL words...such as *SELECT* *INTO* *WHERE* *ORDER BY*

This helps clarify the code

You know, it's the little things in life that makes a difference

Then if you're using Access, make sure that you use the # symbol for your dates otherwise stick to single quotes --> '

Then the field name *date* make sure it isn't a reserved word otherwise it'll create problems...be sure its not otherwise use the [] around the field name

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #3  
Old September 8th, 2003, 06:12 PM
FrequeNC FrequeNC is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: OZ
Posts: 7 FrequeNC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the good advice. I will let you know if that works (when I get a chance to run a test)

I did try to do a Response.Write, but I kept getting errors saying that my syntax was wrong and never got to see what was being output.

What do you mean by using the # symbol for the date? (I am using Access sadly enough...)

Since date is a reserved word I am going to try and rename my field name and see if that helps at all.

Thanks Vince.

Reply With Quote
  #4  
Old September 8th, 2003, 06:44 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
i agree, that using access is sad =P

when editing columns and inserting string literals you use ' ', access for some strange reason uses # # for dates instead.

in asp, variables inside " quotation marks are not interpreted, you'll need to concatenate no matter what.

you can leave it date, just in querys make sure you call it [date], but that's bad programming practive to call the column date, but on the other hand it's good programming practice to use always use []

good luck =)

Reply With Quote
  #5  
Old September 9th, 2003, 04:56 AM
FrequeNC FrequeNC is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: OZ
Posts: 7 FrequeNC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yes access is sad. I started developing the site when I didn't know that much (still don't, just know enough to know that I am not going to redevelop in .asp!) and access was the easiest to start out with. I am rebuilding in php and MySQL. Thanks for the tips. I will give it a go.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > problem using date as filter for record


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 3 hosted by Hostway
Stay green...Green IT