Results 1 to 6 of 6

Thread: like statements with variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    14

    like statements with variables

    hi all,

    I have been trying to use a sql like statement with a variable and it doesn't seem to be working...

    .....fieldname LIKE 'variable%'
    ...... " " variable%
    ...... " " "'variable%'"

    Does anybody know the proper syntax?...I know it's possible to do it in ASP so it has to be possible in VB

    Thanx in advance

    SozeWun

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Hi

    Try something like :


    Dim strSql as string
    Dim lngVar as Long


    strSql="Select ... From....Where fieldname=" & lngVar & " Order By..."

    Just add ' for text and # for dates around them so the resulting string of sql looks right (basic string manipulation - should be the same in ASP).


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here is an example from one of my projects
    VB Code:
    1. sqlstr = "SELECT pa_code, name, street, city, state "
    2. sqlstr = sqlstr & "FROM qcap_dealer WHERE city LIKE '" & txtSrchCity.Text & "%' ORDER BY name"
    Hope this helps.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    14
    here's my sql statement:
    x=txtCriteria.text
    .
    .
    .
    .CommandText = "select CompanyName,PropertyRollNumber from tblMainContactClient CC join tblMainProperty MP on CC.ClientNumber=MP.ClientNumber where MP.PropertyRollNumber LIKE ' " & x & "%' "

    Still doesnt work....i've even tried it in SQL Analyzer....wut am i doing wrong?

    SozeWun

  5. #5
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Just a wild shot in the dark, but PropertyRollNumber is a char/varchar field isn't it? If not, you're probably going to have to cast it before you can use LIKE.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    14
    yup its a varchar...

    Sozewun

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