how to pass my value in query string

RAVI 536 Reputation points


My value will be like this A1,A2,A6

how to pass this in select * from table1 where Field1 storeprocedure so that this can pull all A1 & A2 & A6 data from table

Thanking You

A set of technologies in the .NET Framework for building web applications and XML web services.
3,169 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,252 questions
{count} votes

Accepted answer
  1. QiYou-MSFT 4,306 Reputation points Microsoft Vendor

    Hi @RAVI

    Here is my test table:


    Query String:

    CREATE proc FieldExample @ID1 nvarchar(MAX),@ID2 nvarchar(MAX),@ID3 nvarchar(MAX)
    SELECT*FROM dbo.Test2 WHERE ID in(@ID1,@ID2,@ID3)

    Execute the statement:

    exec FieldExample 'A1','A2','A6'



    Best regards,
    Qi You

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 98,731 Reputation points

    One way is to pass the comma-separated list to SQL Server and then use a function to split it into table format. I have a shorter article on my web site for techniques to do this: Arrays and Lists in SQL Server

    But a better option in my opinion is to pass a table-valued parameter and split the list already in the client. I have an article about this on my web site as well: Using Table-Valued Parameters in SQL Server and .NET

    0 comments No comments