How To Build Dynamic Query Based On Multi Value Parameter?
Hi there, I'm in a bit of a pickle trying to solve this question. How can I dyanimcally build up a sql query based on a varying multi value parameter list? Basically when I run the stored procedure say as below: EXEC test_address 'Smyth', 'A,B,C' I need the query in the stored procedure to be dynamically built such as: SELECT name,address,postcode FROM address_file WHERE name = 'Smyth' AND (postcode LIKE 'A%' OR postcode LIKE 'B%' OR postcode LIKE 'C%') However the issue is that there may not always be 3 postcodes passed in. There could be any number such like: EXEC test_address 'Smyth', 'A,B,C,D,E,F,G' Or even: EXEC test_address 'Smyth', 'Z' How can I dynamically build the 'OR postcode LIKE...' in the WHERE clause to be based on the multi value postcode parameter? TIA