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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:26:46+00:00 2026-05-15T23:26:46+00:00

I have that procedure which returns rows associated by ID with passed argument, i.e

  • 0

I have that procedure which returns rows associated by ID with passed argument, i.e 1,5,7,9

ALTER PROCEDURE [dbo].[get_data]
 @MyCodes as varchar(max) = ''
AS
BEGIN
 DECLARE @query as nvarchar(max)

 set @query = 'SELECT name FROM user WHERE id IN (@p_MyCodes)'

 exec SP_EXECUTESQL @query,
                        N'@p_MyCodes varchar(max)', 
                        @p_MyCodes = @MyCodes
END

That procedure generates an error : Error converting data type varchar to numeric. when I pass as an argument e.g. 3,7,5

What’s wrong ?

  • 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-15T23:26:47+00:00Added an answer on May 15, 2026 at 11:26 pm

    I don’t think this is going to accomplish what you are expecting it to. The error you are getting is because it can’t convert the string ‘3,7,5’ to a number (note that it is NOT trying to parse out your individual values).

    Two ways to get what you want:

    1) Create a table value function that takes a CSV string and returns the results (I’m sure there are many on the web; Here’s a related question: Split function equivalent in T-SQL?). This is nice because you can get rid of the SP_EXECUTESQL sproc call entirely; Your query becomes:

    SELECT name FROM user where id IN (SELECT value FROM dbo.f_Split(@p_MyCodes))
    

    2) Change your set to something like:

    set @query = 'SELECT name FROM user WHERE id in (' + @p_MyCodes + ')'
    

    I don’t recommend #2, it offers a SQL injection hole.

    • 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 which returns either one or no rows (0-1 rows),
I have a stored procedure that returns rows: CREATE PROCEDURE MyProc AS BEGIN SELECT
I have a stored procedure that, depending on the input, returns multiple rows of
I have about thirty strings that get passed to my stored procedure which act
I have this procedure that executes another procedure passed by a parameter and its
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to
I have a stored procedure that returns data in the format of: Date |
I have a stored procedure that returns a dynamic query, e,g if i pass
I have a stored procedure that inserts batches of millions of rows, emerging from
I have a stored procedure that can have 1 to 4 variables passed to

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.