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. Stored Procs, parameters and IN Clause

Stored Procs, parameters and IN Clause

Scheduled Pinned Locked Moved Database
databasequestion
2 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.
  • S Offline
    S Offline
    stephen woolhead
    wrote on last edited by
    #1

    This question relates to MS-SQL 2000 I would like to write a query such as.. SELECT * FROM Users WHERE id IN @UserIDs Where @UserIDs is a list of integers passed into the stored proc. Is this possible? The list of ID's is generated by a user, so I cant use a sub query to get the required list of ID's. If it is possible, what type do I define the parameter as? Thanks Stephen

    J 1 Reply Last reply
    0
    • S stephen woolhead

      This question relates to MS-SQL 2000 I would like to write a query such as.. SELECT * FROM Users WHERE id IN @UserIDs Where @UserIDs is a list of integers passed into the stored proc. Is this possible? The list of ID's is generated by a user, so I cant use a sub query to get the required list of ID's. If it is possible, what type do I define the parameter as? Thanks Stephen

      J Offline
      J Offline
      jeff_martin
      wrote on last edited by
      #2

      There is a way, but I don't recommend it. For one thing, you lose out on one of the key reasons for using a stored proc...the pre-compilation by SQL Server. Here's how you do it.... create procedure dbo.usp_Test ( @ids varchar(100) ) as declare @sql as varchar(255) set @sql = 'select * from table where tableid in (' + @ids + ')' exec(@sql) GO then you pass the ids in as a comma delimited string... exec usp_Test '1000, 1001, 1010'

      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