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 8720247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:59:34+00:00 2026-06-13T06:59:34+00:00

I have an ASP.NET website (c#) and in the code-behind I want to use

  • 0

I have an ASP.NET website (c#) and in the code-behind I want to use the IN operator in SQL http://www.w3schools.com/sql/sql_in.asp to get data from my database.

The syntax is:

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)

I use a stored procedure to get data, inside this procedure I run, in the end, the select.

My question is how to build dynamically the (value1, value2, ...) part of the query? How do I send as SqlParameter(s) the values that appear in the IN operator?

The stored procedure is defined like this:

CREATE PROCEDURE [dbo].[GetAllUsers]
    @ORGANIZATION_ID int = null
AS
BEGIN
    SET NOCOUNT ON;

    begin
       SELECT * 
       from USERS
       where ORGANIZATION_ID = @ORGANIZATION_ID
    end
END

I’d like to replace the WHERE clause with something like:

WHERE ORGANIZATION in (xxxxxxxxxxxxx)

How to do this?

Thank you.

  • 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-06-13T06:59:36+00:00Added an answer on June 13, 2026 at 6:59 am

    You can use dynamic sql:

    CREATE PROCEDURE [dbo].[GetAllUsers]
        @ORGANIZATION_ID varchar(max) = null
    AS
    BEGIN
        declare @sql varchar(max)
        @sql = 'SELECT * 
                from USERS
                where ORGANIZATION_ID in ('+@ORGANIZATION_ID+')' 
        SET NOCOUNT ON;
            begin
              exec(@sql)  
            end
    END
    

    You have to change type of @ORGANIZATION_ID to varchar and run the procedure with

    one id:

    exec '1' 
    

    or list of ids:

    exec '1,2,3,4' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net website with c# code behind and using visual studio 2010.
I have an ASP.NET website (c# as code behind) in which one of my
In my Asp.net website I have a repeater which loads dynamically from code-behind. In
i have an asp.net website where i do paging through on the code behind
I have a asp.net project with c# code behind. I have a static class
In asp.net website, inside .aspx i have following code <script type=text/javascript> function callme(option) {
I have a function in the code behind of an ASP.NET webpage that creates
I currently have an asp.net website hosted on two web servers that sit behind
I have several ASP.NET websites in a solution along with a common C# code
I have an ASP.NET web site with something similar to the following code: .aspx

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.