...

View Full Version : use value of text field in SQL statement



parallon
03-29-2006, 08:56 PM
Hello all. I am trying to filter items in my table based on the date in a text box, and I was wondering how I would go about doing that?

Here is what I have so far:


SELECT Hours
FROM tblEmpTime
WHERE dbEmpLogin = 'MMColParam' AND WorkDate = "txtDate.value"

The name of the form is 'frmDate' and the textfield is 'txtDate'

Thanks,

Parallon

GJay
03-29-2006, 09:24 PM
It might help to say what language you're using...

parallon
03-29-2006, 10:01 PM
I'm sorry. I am using ASP.

Thanks

guelphdad
03-30-2006, 03:40 AM
I would say you need to ask the moderators to move the thread to the ASP forum for you. if you know how to do what you need in mysql itself then it is a matter of your ASP coding being right and thus not a question for the mysql forum itself.

vinyl-junkie
03-30-2006, 05:51 AM
I've been away from ASP a bit too long to be able to tell you for sure how your variable should be referenced, but I do know that you need form your query with hash marks around the date itself. For example:

#3/1/2006#

Hope this helps.

raf
03-30-2006, 07:31 AM
In asp, that would be


dim sql
sql = "SELECT Hours FROM tblEmpTime WHERE dbEmpLogin = 'MMColParam' AND WorkDate = '" & Request.Form("txtDate") & "'"

note that in MySQL, dates need to be in the format yyyy-mm-dd .
surrounding the dates with # is a JetSQL deviation --> for MySQL, like for almost every other db, you just need to surround the values with quotes.

parallon
03-30-2006, 05:15 PM
Thank you. I will give this a try.

Parallon

parallon
03-30-2006, 11:02 PM
Ok, I think that I have run into a problem. The text field that I need the date from is on the same page as the displayed info. Here is how it works. I have a page PickWeek.asp in which the user will either pick 'Last Week' or 'This Week'. From there, they will be shown a confirmation page showing the start and end date of the week that they chose. All dates for the 7 days are also stored in variables. When they click OK, each of these variables are written to a temporary table, and they are taken to the first day of the week (separate page for each day). Well, the correct date is displayed on each day of the week by calling from the appropriate field in the database. So, what I need to do is to either filter based on the date in the text field on the top of the page, or filter based on the date coming from the database. Either way, I don't know how to pull from a text field on the same page as the SQL statement, or to include the value from the database. If I could guarantee that they would access the pages in order, then I could just pull the dates from the previous page.

I hope this makes sense.

Thanks,

Parallon

raf
03-31-2006, 07:06 AM
I didn't realy understand that explanation.

I wonder why you keep on posting about these ASP issues in the MySQL forum. As noted above: ask a moderator to move this thread to the ASP forum + please start a new thread for each seperate problem.

vinyl-junkie
03-31-2006, 01:17 PM
I wonder why you keep on posting about these ASP issues in the MySQL forum. As noted above: ask a moderator to move this thread to the ASP forum + please start a new thread for each seperate problem.
I asked a couple of days ago about getting the thread moved. Apparently, the mods think this thread belongs right where it is.

As for starting a new thread, I really think it's unnecessary. I see the latest question as an extension of the original one.

Brandoe85
03-31-2006, 02:25 PM
Ok, we'll get this moved to the asp forum.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum