Passing a CSV List Within an IN Statement

Passing a CSV List Within an IN Statement

I have a CSV list I am passing through as a parameter in a stored procedure.

-------------------------------Example of Region list:1,2,3,4,5,6,7,8,9,10CREATE PROCEDURE sp_getReport   @Regionlist 
varchar(100) AS .......Select * from tblRegionwhere Region_ID IN (@regionlist)---------------------------------

The varchar treats the list as one block of data. How can I change my code/syntax to read each value of the list separately within the IN statement?

When you pass variables that are part of the statement in a stored procedure, you need to use the EXEC(UTE) statement. Here’s the syntax to call the stored procedure and modify the current stored procedure to take the regions list as a parameter (the only difference is I called the column RegionID instead of Region_ID):

sp_getreport '1,2,3,4,5,6,7,8,9,10'CREATE PROCEDURE sp_getReport   @regionlist varchar(100) ASEXEC ('Select * from tblRegion where RegionID IN 
(' + @regionlist +')')

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several