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

  • Home
  • SEARCH
  • 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 6888937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:05:30+00:00 2026-05-27T06:05:30+00:00

When I try this query it works: SELECT * FROM tbl_Users WHERE UserId IN

  • 0

When I try this query it works:

SELECT *
FROM tbl_Users
WHERE UserId IN (555, 3695, 8787))

But when I put it in stored procedure it get value only if I pass one ID. If I pass more ID’s

I got nothing returned from database:

CREATE PROCEDURE myStoredProcedure
    @m_UserIdList varchar(500)
AS    
    SELECT u.*, p.*
    FROM tbl_Users u 
    INNER JOIN tbl_Bunker b 
    ON u.BunkerId = b.Bunker
    WHERE u.UserId IN (@m_UserIdList)
  • 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. Editorial Team
    Editorial Team
    2026-05-27T06:05:31+00:00Added an answer on May 27, 2026 at 6:05 am

    Yes, it is treating @m_UserIdList as one single value and comparing that to u.UserId. You need to split out the values and test them separately. Oded beat me to the punch, but he is right — you should use a table-valued param. Here is the link from Oded:

    http://www.sommarskog.se/arrays-in-sql-2008.html

    This site offers a bunch of different approaches to this problem:

    http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm

    One of the approaches would be to use dynamic SQL, however you should be aware of the dangers of doing this. Read this first:

    http://www.sommarskog.se/dynamic_sql.html

    If you decide to go that route, something like this could work:

    DECLARE @SQL varchar(600)
    
    SET @SQL = 
    'SELECT u.*, p.*
    FROM tbl_Users u
        INNER JOIN tbl_Bunker b ON u.BunkerId = b.Bunker
    WHERE u.UserId IN (' + @m_UserIdList+ ')'
    
    EXEC(@SQL)  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which works but when I try to write the equivalent
If I try to run this query in SQL Server 2005: SELECT 1 WHERE
This query works: SELECT Article.id, Article.post_time, Article.post_locked, Article.comments_locked, Article.title, IF(CHAR_LENGTH(Article.content)>2000, RPAD(LEFT(Article.content,2000),2003,'.'), Article.content) as content,
I have this nhibernate query: var q = NHibernateSession.Current.CreateSQLQuery ( @SELECT LastestEvents.* FROM (
I have a query which works, goes like this: Select count(InsuranceOrderLine.AntallPotensiale) as potensiale, COUNT(InsuranceOrderLine.AntallSolgt)
I've a this query in mySQL (MyISAM): SELECT * FROM `links` WHERE `id` IN
i've got this stored procudure that won't work. If I try this query in
I'm trying ro execute this dql query SELECT DISTINCT a FROM Ipf\Model\Entity\Transaction t INNER
I have a query similar to this: SELECT itemID FROM itemTable WHERE itemID LIKE
I have the following query I use and it works great: SELECT * FROM

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.