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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:51:05+00:00 2026-05-21T13:51:05+00:00

I have an SP that has an nvarchar(max) parameter @p1 . This is a

  • 0

I have an SP that has an nvarchar(max) parameter @p1. This is a comma separated list of codes e.g. 100,200,300 etc

Inside the SP I declare a variable @p2 nvarchar(max) and convert the @p1 list into a single quoted list

set @p2 = N'''' + replace(@p1,',',''',''') + ''''

When I “select” @p2 this returns the correct '100', '200', '300'

If I then use @p2 in a subselect, e.g

select x,y,z from table1 where id in (@p2) 

I get no rows returned? If I modify the same SQL to use the same string literal I got from the previous select I get the rows ok?

How can I pass a string containing a list of single quoted identifiers to a SP and use this in a subselect? I’ve Googled this extensively, and it is possible to convert the list to a temporary table inside the SP and use this, but I need to use the quoted list so I can use an OPTIMIZE FOR query hint.

  • 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-21T13:51:06+00:00Added an answer on May 21, 2026 at 1:51 pm

    IN does not work with comma-separated strings the way you expect: it is considered a single string, not an implicit array of values.

    id IN ('101,102,103') will only match if id is exact string '101,102,103', not any of its individual separated chunks.

    You should implement a TVF which splits the string and returns a set of its members and use it like that:

    SELECT  *
    FROM    table1
    WHERE   id IN
            (
            SELECT  value
            FROM    tvf_split_string('101,102,103')
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a SQL server column of type nvarchar(max) which has text that
I have a small 20-row table in my SQL08-R2 database that has an nvarchar(max)
I have a simple table (lets call it Table1) that has a NVARCHAR field
I have a stored procedure that has a parameter called UserName and in my
I have a column [Cash] nvarchar(50) that has data that will later be converted
I have a NVARCHAR(max) column in a table and a stored procedure that would
I have a column of type 'nvarchar(max)' that should now hold XML information instead
I have program that has a variable that should never change. However, somehow, it
I have two tables: object that has object_id column and avalues that have object_id
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton

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.