Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

SQL query...need help quick

  • 30-03-2006 05:54PM
    #1
    Registered Users, Registered Users 2 Posts: 224 ✭✭


    Hi All, Im in desperate need of help here

    I need to create a select statement that works(for starters).

    basically I have 6 options in the search.
    1st field is a wild card field i.e. Keyword
    2nd field is from a dropdown list i.e. catagories
    3rd field is a text field where you enter a customer name

    4th, 5th & 6th are text fields for codes. So they need to be absolute (if you get my drift).

    I tried the following statement but its not working correctly

    ******************************
    SELECT *
    FROM dbo.qryProdSearch
    WHERE ItemDesc LIKE '%rsSearch%' AND CustName LIKE '%rsSearch1' AND SuppCode Like '%rsSearch2%' AND SCode LIKE '%rsSearch3%' AND GroupID LIKE '%rsSearch4%' AND SItemID LIKE '%rsSearch5%'

    **********************

    And these are the fields I declared

    ********************************

    <%
    Dim rsSearchRes__rsSearch
    rsSearchRes__rsSearch = "%"
    If (Request.QueryString("txtSearch") <> "") Then
    rsSearchRes__rsSearch = Request.QueryString("txtSearch")
    End If
    %>
    <%
    Dim rsSearchRes__rsSearch1
    rsSearchRes__rsSearch1 = "%"
    If (Request.QueryString("txtSupplier") <> "") Then
    rsSearchRes__rsSearch1 = Request.QueryString("txtCust")
    End If
    %>
    <%
    Dim rsSearchRes__rsSearch2
    rsSearchRes__rsSearch2 = "%"
    If (Request.QueryString("txtSuppCode") <> "") Then
    rsSearchRes__rsSearch2 = Request.QueryString("txtSuppCode")
    End If
    %>
    <%
    Dim rsSearchRes__rsSearch3
    rsSearchRes__rsSearch3 = "%"
    If (Request.QueryString("txtSCode") <> "") Then
    rsSearchRes__rsSearch3 = Request.QueryString("txtSCode")
    End If
    %>
    <%
    Dim rsSearchRes__rsSearch4
    rsSearchRes__rsSearch4 = "%"
    If (Request.QueryString("txtgroupid") <> "") Then
    rsSearchRes__rsSearch4 = Request.QueryString("txtgroupid")
    End If
    %>
    <%
    Dim rsSearchRes__rsSearch5
    rsSearchRes__rsSearch5 = "%"
    If (Request.QueryString("txtitemid") <> "") Then
    rsSearchRes__rsSearch5 = Request.QueryString("txtitemid")
    End If
    %>


    ****************************
    Any ideas...all very welcome


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,215 Mod ✭✭✭✭Seth Brundle


    I presume its ASP & MSSQL
    is the SQL running from your ASP?
    Are you using double quotes to concatenate variables to your string?
    What is the difference between rsSearchRes__rsSearch and rsSearch?

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    SELECT *
    FROM dbo.qryProdSearch
    WHERE ItemDesc LIKE '%rsSearch%' AND CustName LIKE '%rsSearch1' AND SuppCode Like '%rsSearch2%' AND SCode LIKE '%rsSearch3%' AND GroupID LIKE '%rsSearch4%' AND SItemID LIKE '%rsSearch5%'
    
    Looks to me like this is going to search on the literal values "%rsSearch%" and so forth, rather than using the values in the variables of the same name.

    How you assign values to the vars (teh code you supplied) isn't of much relevance. Its how you build the SQL string and eubsequently execute it thats of interest.

    jc


Advertisement