Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a code in JS which is pushing value to a comma separated string if that value do not exist in the list.
I want the similar thing into SQL Server also.

What I have tried:

I am able to make comma separated list into column with values, i am converting list into a temp table and checking one by if new numbers exists.

Is there any better way to perform this? Please help me finding.
Posted
Updated 2-Jun-16 1:04am
Comments
CHill60 2-Jun-16 6:52am    
Share the code you are using. Yes there are better ways of doing this

1 solution

It's generally a bad idea to store comma separated lists in SQL at all, yopu woudl probably be better off with a second table and a foreign key.
But...
SQL
UPDATE MyTable SET MyColumn = MyColumn + ',' + 'My new item' WHERE MyIDColumn=MyIDValue
Takign one back out again is a much, much harder process - which is one of the reasons why the second table is a much better design.
 
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