#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Using LIKE '%variable%' with a parameterized query


    I am trying to accomplish something like...

    SELECT ItemID, ItemNumber, ItemDesc FROM ITEMS WHERE ItemDesc LIKE '%variable%'

    The problem is I am using a parameterized query, so it is structure like...

    rsItems_cmd.CommandText = "SELECT ItemID, ItemNumber, ItemDesc FROM ITEMS WHERE ItemDesc LIKE ?"

    and then passing the parameter...

    rsItems_cmd.Parameters.Append rsItems_cmd.CreateParameter("param1", 200, 1, 50, rsItems__Variable

    (Where rsItems__Variable is a string of the value passed)

    How do I use a LIKE command when passing a text string as a parameter??
  2. #2
  3. 0x800A0C93
    ASP Super Hero (2500 - 2999 posts)

    Join Date
    Jan 2009
    Location
    Ridin' through this world...
    Posts
    2,975
    Rep Power
    1310
    Try:

    'set the variable with initial value
    rsItems__Variable= source of whereever it is coming from

    'append the %'s to it before feeding it to the query
    rsItems__Variable= "%" & rsItems__Variable & "%"
    Brinkster- free development account. Not affiliated, but I sure like free. Brinkster.com

Similar Threads

  1. Parameterized Query - Must declare the variable
    By Nishana in forum ASP Development
    Replies: 12
    Last Post: June 4th, 2009, 03:41 AM
  2. Problem with Parameterized Query
    By Computer-bot in forum ASP Development
    Replies: 1
    Last Post: December 27th, 2007, 02:22 PM
  3. Variables of Parameterized query
    By Computer-bot in forum ASP Development
    Replies: 3
    Last Post: December 27th, 2007, 01:59 AM
  4. Parameterized Query
    By Computer-bot in forum ASP Development
    Replies: 18
    Last Post: October 21st, 2007, 08:04 AM
  5. Parameterized SQL Query
    By rmoghal in forum .NET Development
    Replies: 4
    Last Post: June 15th, 2005, 03:28 PM

IMN logo majestic logo threadwatch logo seochat tools logo