Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    use value of text field in SQL statement

    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:

    Code:
    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

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    It might help to say what language you're using...

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    I'm sorry. I am using ASP.

    Thanks

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #5
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    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.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In asp, that would be
    Code:
    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you. I will give this a try.

    Parallon

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #10
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Quote Originally Posted by raf
    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.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #11
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Ok, we'll get this moved to the asp forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •