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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:40:57+00:00 2026-05-27T20:40:57+00:00

I have a stored procedure which need to run IN statement. I want to

  • 0

I have a stored procedure which need to run IN statement. I want to know a way to convert a string (list of comma separated integers) to int. In this example, positionID needs to be converted. Please help. Thanks

Here is my stored procedure:

Create PROCEDURE [dbo].[spCount]
    @year varchar(50),
    @positionID varchar(50)
AS
BEGIN

Select
    ApplicantID, [Name], PositionID, COUNT(*) AS Votes
                       FROM          dbo.vwLog
                       WHERE Year = @year And PositionID in (@positionID)
                       GROUP BY ApplicantID, [Name], PositionID
                        Order By PositionID, Votes DESC
END
  • 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-27T20:40:58+00:00Added an answer on May 27, 2026 at 8:40 pm

    You can take advantage of the fact that SQL Server 2008 now supports table types. You can define a table type and on the .net side construct a DataTable and pass that as a parameter to your stored procedure. On the SP side that parameter is of type [whatever tabletype you made] Here is an example.

    TotalPositions = [Some List] //of CSV List
    DataTable Positions = new DataTable(); //Create the Datatype
    Positions.Columns.Add("PositionID", typeof(int)); //
    foreach (string sPos in TotalPositions.Split(','))
    Positions.Rows.Add(int.Parse(sPos)); 
    

    You can then Append Positions as a parameter for your stored procedure

    SqlParameter Param = new SqlParameter();
    Param.Value = Positions
    Param.SqlDbType = SqlDbType.Structured;
    Param.ParameterName = @Positions                    
    command.Parameters.Add(Param);
    

    In your database you have to define a table type as

    CREATE TYPE [dbo].[Positions] AS TABLE(
        [Position] int NULL,
    )
    GO
    

    and in your stored procedure add

    @MyPositions Positions Readonly
    

    Now you can treat @MyPositions as a table in your procedure and compare to it.

    • 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 in which i want to create a user defined
I need to run a stored procedure for every item in a list (from
I have a weird requirement which I need to use inside my Stored Procedure
I have a stored procedure which takes an XML parameter and inserts the data
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a stored procedure which basically does something like select top 1 expiryDate,
I have a stored procedure which is doing a lot of delete. Hundreds of
I have a stored procedure which executes another procedure inside it. The second one
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
I have a messy stored procedure which uses dynamic sql. I can debug it

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.