Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL using Like operator for prepared statement

SQL using Like operator for prepared statement

Scheduled Pinned Locked Moved Database
databasetutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    Hi all~ E.g "Select * from table_A where firstName Like '%" + string + "%'"; How to change the ad-hoc sql to prepared statement using operator 'like' and '%'? Thanks

    G T 2 Replies Last reply
    0
    • T ting668

      Hi all~ E.g "Select * from table_A where firstName Like '%" + string + "%'"; How to change the ad-hoc sql to prepared statement using operator 'like' and '%'? Thanks

      G Offline
      G Offline
      GreggS
      wrote on last edited by
      #2

      Not sure what you mean, but have a look at the sp_executesql stored procedure. That may point you in the general direction


      Gregg

      1 Reply Last reply
      0
      • T ting668

        Hi all~ E.g "Select * from table_A where firstName Like '%" + string + "%'"; How to change the ad-hoc sql to prepared statement using operator 'like' and '%'? Thanks

        T Offline
        T Offline
        ting668
        wrote on last edited by
        #3

        If using prepared statement, The sql will like this: cmd.CommandText = "Select * from table_A where firstName Like ?" cmd.Parameter.Add("FirstName", "John"); cmd.Prepared(); cmd.ExecuteNonQuery(); Then if I would like to get the records which the firstName contains string "John". Using ad-hoc statement, "%" operator can be used. If using prepared statement, but to put "%" operator or using other way to achieve the result.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups