Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 147133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:43:39+00:00 2026-05-11T08:43:39+00:00

I have a stored procedure that takes a comma-delimited string of IDs. I split

  • 0

I have a stored procedure that takes a comma-delimited string of IDs. I split them and put them into a temporary table and pull out records from another table using where id IN [table]

Is it ok to use this same procedure when only one id is passed in for the param? I could write a second stored procedure that would do exactly the samething but instead do where id = @id.

I have MANY stored procedures where multiple IDs or just one could be passed in. Do I try to reuse the existing procedures or write new ones? Is the performance hit significant?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:43:40+00:00Added an answer on May 11, 2026 at 8:43 am

    You might like to try a JOIN instead of WHERE id IN – although I think you will get the same query plan.

    So I assume you are doing:

    SELECT COl1, Col2, ... FROM MyTable WHERE id IN (SELECT id FROM @MyTempTable) 

    in which case the equivalent JOIN syntax would be :

    SELECT COl1, Col2, ... FROM  MyTable AS T1      JOIN @MyTempTable AS T2          ON T2.id = T1.id 

    and in the second case whether there is 1, or many rows, it will be very effective provided [id] is indexed (I am assuming it is the PK on your table, and using a Clustered Index).

    (Beware that if you have DUP IDs in @MyTempTable you will wind up getting dupes from MyTable as well 🙁 )

    For best performance it would be worth explicitly declaring [id] as the PK on your temporary table (but given it only holds a few rows it probably won’t make much odds)

    DECLARE @TempTable TABLE (     id int NOT NULL,     PRIMARY KEY     (         id     ) ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that takes a string of a pipe delimited array
I have a stored procedure that takes in the name of a table as
I have a stored procedure in my database that takes a table value parameter,
I have a stored procedure that takes care of updates to my person table.
I have a stored procedure that takes a user ID and calculates their balance
I have a stored procedure that takes no parameters, and it returns two fields.
I have a stored procedure that returns values from a temp table. In my
I have a stored procedure that takes an XML parameter and inserts the Entity
I am trying to write a stored procedure that takes a table name as
I have a stored procedure in MS SQL, that takes 2 parameteres, for example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.