Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have table branch and an another table pincode with a column which can contain pincode IDs separated with comma as varchar data type. I want to Select related pincodes based on branch id but I'm getting error "Conversion failed when converting the varchar value '1,3,5,' to data type int." when trying to select:

SELECT Pincode from tblpin where pinID in (select pinid from branch where brnchID='1');

The subquery returns data like "1,3,5"
Posted

1 solution

You can;t do it like that: SQL deos not understand comma separated data except in specific places - and a data column value is not one of them.
It's possible - but a pain: Using comma separated value parameter strings in SQL IN clauses[^]

A much, much better solution is not to store ID as strings at all, but set up a separate table linking them instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900