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. Passing multiple values to a select statement

Passing multiple values to a select statement

Scheduled Pinned Locked Moved Database
databasequestioncsharpperformancetutorial
3 Posts 3 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.
  • M Offline
    M Offline
    Mel Padden
    wrote on last edited by
    #1

    Hi, not an expert SQL programmer so apologies if this seems like a novice question... Is there a way to pass multiple parameters to a select statement in an SQL stored procedure? For example: Say you wish to select all addresses in a certain county, where the counties table is foreign-keyed to the Address table on ID. So you would write a stored proc to accept a single county ID, and select on that basis. But say you want to pass in a range of counties, and select all addresses with a county ID in that range? It's easy to do in inline SQL, using the IN operator, so I could build a SQL string in my data access class and pass that for direct execution to the DB engine, but I'd rather stay away from that approach for obvious reasons. The other option is to not select on county, pass all results to my .NET class, and filter the data using my list of selection values in code before passing the resultset to the client. I think I'd prefer the latter approach but if it were possible I'd like to do the whole lot in SQL to enhance performance. It's an MS SQL 2000 database. Does anyone out there know of a way to get around this?

    All the dude ever wanted... was his rug back.

    G A 2 Replies Last reply
    0
    • M Mel Padden

      Hi, not an expert SQL programmer so apologies if this seems like a novice question... Is there a way to pass multiple parameters to a select statement in an SQL stored procedure? For example: Say you wish to select all addresses in a certain county, where the counties table is foreign-keyed to the Address table on ID. So you would write a stored proc to accept a single county ID, and select on that basis. But say you want to pass in a range of counties, and select all addresses with a county ID in that range? It's easy to do in inline SQL, using the IN operator, so I could build a SQL string in my data access class and pass that for direct execution to the DB engine, but I'd rather stay away from that approach for obvious reasons. The other option is to not select on county, pass all results to my .NET class, and filter the data using my list of selection values in code before passing the resultset to the client. I think I'd prefer the latter approach but if it were possible I'd like to do the whole lot in SQL to enhance performance. It's an MS SQL 2000 database. Does anyone out there know of a way to get around this?

      All the dude ever wanted... was his rug back.

      G Offline
      G Offline
      ganti r
      wrote on last edited by
      #2

      Hi, You can do some thing like this. Create Procedure @CountyID varchar(100) Begin Exec ('Select * from CountyTable where countyId in ('+@CountyID+')') End Where @CountyID contains the comma separated list of countyId's Hope this helps you.

      rAm i Think, i Wait, i Fast -- Siddartha

      1 Reply Last reply
      0
      • M Mel Padden

        Hi, not an expert SQL programmer so apologies if this seems like a novice question... Is there a way to pass multiple parameters to a select statement in an SQL stored procedure? For example: Say you wish to select all addresses in a certain county, where the counties table is foreign-keyed to the Address table on ID. So you would write a stored proc to accept a single county ID, and select on that basis. But say you want to pass in a range of counties, and select all addresses with a county ID in that range? It's easy to do in inline SQL, using the IN operator, so I could build a SQL string in my data access class and pass that for direct execution to the DB engine, but I'd rather stay away from that approach for obvious reasons. The other option is to not select on county, pass all results to my .NET class, and filter the data using my list of selection values in code before passing the resultset to the client. I think I'd prefer the latter approach but if it were possible I'd like to do the whole lot in SQL to enhance performance. It's an MS SQL 2000 database. Does anyone out there know of a way to get around this?

        All the dude ever wanted... was his rug back.

        A Offline
        A Offline
        Arun Immanuel
        wrote on last edited by
        #3

        Yes, it is possible. There are 3 ways to do this as mentioned here : Click Here[^]

        Regards, Arun Kumar.A

        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