Thursday 22 June 2017

Converting lists for use in a SQL 'IN' statement

This website is a massive time saver http://delim.co/ 

Simply paste your list into the textbox, then select you delimiter (comma) then under converter options enter a single quote into open tag and close tag.

This will then produce a list of single quote enclosed comma separated values that you can drop straight into your SQL IN statement

Step 1
A1
B1
A2
B2
A3

B3

Step 2
'A1','B1','A2','B2','A3','B3'

Step 3
Select * from Product where ProductCode IN ('A1','B1','A2','B2','A3','B3')