Results 1 to 12 of 12

Thread: Putting a parameter in search query

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Putting a parameter in search query

    Hello, I have a query in my sql builder like this

    Code:
    SELECT    *
    FROM            canvasstable
    WHERE        (Material_Description LIKE '%a%')
    That code is 100% working. My problem is I cant change it to something like this

    Code:
    SELECT    *
    FROM            canvasstable
    WHERE        (Material_Description LIKE '%' + @parameters +'%')
    I also tried something like this

    Code:
    WHERE        (Material_Description LIKE CONCAT(@param, '%') AND = CONCAT('%', @param)
    Please Help I really need it as much as possible. This is for our system.

  2. #2
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Putting a parameter in search query

    1) Is it MySQL,
    2) Is it is in STORED PROCEDURE
    3) are you trying to pass the SQL via front end

    the simple way is pass the parameter value with %

    some thing like this
    Code:
    SELECT * FROM TABLE WHERE TABLE.CRITERIA LIKE @PARAM;
    IF in side the UD_SP then
    @PARAM = CONCAT('%',YOUR_PARAMETER,'%')
    IF you are executing the SQL from front end ( via ADO ) then also the thing is same
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Putting a parameter in search query

    try this:
    Code:
    (Material_Description LIKE ('%' + @parameters +'%'))
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Thanks tg

    Code:
    1) Is it MySQL,
    2) Is it is in STORED PROCEDURE
    3) are you trying to pass the SQL via front end
    
    IF you are executing the SQL from front end ( via ADO ) then also the thing is same
    1. Yes
    2. No
    3. I think no, not sure.

    I'm using creating it in this




    then calling it in the event of the textbox textchange.

    Thanks TG I really need it as much as possible because the defense of our system will be on monday, now it is friday 1:00am in the philippines.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Putting a parameter in search query

    I can tell from the screen shot there that you didn't followclose enough... the parenthesis should be AFTER the like... not before...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Oops! Sorry for that. I just intended to show you the way of how I use the query to answer your question number 3 "3) are you trying to pass the SQL via front end"

    The screenshot you see is the query that I'm experimenting.

    By the way
    Code:
    (Material_Description LIKE ('%' + @parameters +'%'))
    doesnt work


    Everytime I enter in the query builder this code

    Code:
    (Material_Description LIKE ('%' + @parameters +'%'))
    Then by pressing execute query the query automatically becomes like this, and error are popping.

    Code:
    (Material_Description LIKE '%' + @parameters + '%')
    Last edited by cary1234; Oct 6th, 2011 at 12:33 PM. Reason: Forgot something

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Oops, sorry make_me_rain i though you are techgnome. Im just in a hurry.

    this answer is for you.

    Code:
    1) Is it MySQL,
    2) Is it is in STORED PROCEDURE
    3) are you trying to pass the SQL via front end
    
    IF you are executing the SQL from front end ( via ADO ) then also the thing is same
    1. Yes
    2. No
    3. I think no, not sure.

    I'm creating it in this




    then calling it in the event of the textbox textchange.

  8. #8
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Putting a parameter in search query

    This is a query builder IDE!!, just as QBE in access,
    lets say like this

    vb Code:
    1. Dim SQL As String = _
    2.         "SELECT Material_Description FROM yourTable WHERE yourTable.Material_Description " _
    3.         & " LIKE @PARAM"
    4.  
    5.         Dim Input_Param As String = "% " & "Some Parameter" & " % "

    do not go for the QBE
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Code:
        Dim SQL As String = _
                "SELECT Material_Description FROM yourTable WHERE yourTable.Material_Description " _
                & " LIKE @PARAM)"
         
                Dim Input_Param As String = "% " & "Some Parameter" & " % "

    I will type those codes inside the event in vb.net??? I cant understand how to use those code. haha! Thanks make me rain.

  10. #10
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Putting a parameter in search query

    i didn't fallow you CARY, what you said & what you are trying for,
    Ok any how good night, see u later
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Hmm.. Strange.. Anyways thanks make me rain. Good night! Catch u later!

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2009
    Posts
    253

    Re: Putting a parameter in search query

    Anybody here? Help urgently needed. Please.

Posting Permissions

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



Click Here to Expand Forum to Full Width