Stupid Question SQL Searching

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Stupid Question Re:SQL Searching

    I have a database full of names and contact info. The names are split into last
    and first, as would be expected. I would like to create an idiot-proof method
    of searching for people in the DB, using 1 form only. A person would then be
    able to enter first name, last name, first and last, etc. I can get the first
    name search working (John), and I can get the last name search working (Doe),
    but I can't think of how to form a query that would take care of a first AND
    last name search (John Doe) since they are in different fields. I'm sure it's
    something stupid I'm overlooking, but a push in the right direction would be
    appreciated.

    Thanks!

    dmurray1414 Guest

  2. Similar Questions and Discussions

    1. Stupid Question??
      I have written a class to be used by asp.net applications that provides a useful function. Other than the constructor, it has just one method. ...
    2. really really stupid question
      So I made an animation for my website and I want it to run it ionce n the beginning when people go to the home page. Also, I'd like a little box...
    3. OK. I'm asking a stupid question
      I created a multi-frame movie to use as my website. It has five buttons on it which I added the Get URL action to. When I publish it, and then open...
    4. Stupid C# question Please help!
      I'm used to writing my code in VBscript but I have to do this project in C#. I've written some functions on my ASP.Net page and I'm getting an...
    5. Is this a stupid question?
      I'm looking for the command to direct a user to a new URL. For example, in ASP, when you created a dropdown box, the item selected could open a...
  3. #2

    Default Re: Stupid Question Re:SQL Searching

    SELECT whatever
    FROM data table
    WHERE firstname = form.firstname AND lastname = form.lastname
    ORDER however
    etc...
    Damnit Spock! Guest

  4. #3

    Default Re: Stupid Question Re:SQL Searching

    Thanks, but not quite what I'm looking for. I only have one form on the search
    page, not one for first name and one for last. It works fine for searching by
    last name only or first name only, but if someone enters a first name AND a
    last name, I don't know what to do since the name is seperated into first and
    last in the DB.

    dmurray1414 Guest

  5. #4

    Default Re: Stupid Question Re:SQL Searching

    You only have one "textbox" on the form? Don't you have one box for "firstName" and a separate field for "lastName"?
    mxstu Guest

  6. #5

    Default Re: Stupid Question Re:SQL Searching

    Assuming you meant you had one field on your form, I have a stupid question for
    you, how do you know if the person typed a first name or last name in the field?

    If they type both, separated by a space, then do that. Separate the form
    field value into two variables on the space (look up functions find, left, and
    right for how to do this) and use that in your where clause.

    JR


    jonwrob Guest

  7. #6

    Default Re: Stupid Question Re:SQL Searching

    jonwrob,

    Not to mention how do you know if the user typed: firstname (space) last name -OR- lastname (space) first name, and what happens if either name has a space in it?
    mxstu Guest

  8. #7

    Default Re: Stupid Question Re:SQL Searching

    That's a fair point.

    To the OP: You really need to think about how you want your search form to
    deal with those issues.

    The one additional thing you might want to consider, would be to concatenate
    your first and last name columns. I don't know what db your using. In Oracle,
    the concatenation operator is ||, so you could search your two columns as one
    like:

    firstname || lastname
    or even
    firstname || ' ' || lastname

    JR


    jonwrob Guest

  9. #8

    Default Re: Stupid Question Re:SQL Searching

    Thanks for the replies guys. It's like this - I want to have an address book
    database searchable, but I want to make it easy. I would rather spend more time
    making it simple now than deal with people who can't figure it out later.
    Therefore, I would like only one text box to search for a name. Right now, I
    have it working so that you can enter either a first name or last name and it
    will find anyone who matches that. That was simple using WHERE first =
    '#text.text#' OR WHERE last = '#text.text#' . I am counting on people also
    trying to enter the full name instead of just first or last, and I need to be
    able to have it respond to that. So, if someone asks for "John Doe" I need to
    have my query be able to match it to an entry that has a "Doe" last name and a
    "John" first name. I just don't know how to write that. Make sense?

    Dan

    dmurray1414 Guest

  10. #9

    Default Re: Stupid Question Re:SQL Searching

    Hi

    You could first concatenate the entered text :
    Like if I entered AAA XXX YYY as the name
    you could strip this text as AAA,XXX,YYY

    in the query you could write firstname in ( AAA,XXX,YYY) or lastname in
    (AAA,XXX,YYY)

    Anj

    Anj01 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139