Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am manage all record by id. Add Record in column in table only product Id with separate comma.
Expamle

ProductId:-
15,11,16,22,21,8,13,1,12,7,9,19,4

Searching for record which is best Where condition or cursor ?

Suggest me






Brijesh Kumar
*********

[Edit]: Removed Mobile number
Posted
Updated 10-Jun-14 2:55am
v2
Comments
CHill60 10-Jun-14 8:04am    
Is that a list of ids in your table? Where are the commas coming from?

1 solution

Don't.
storing commas separated strings of ids is a bad idea: it makes them a nightmare to use as SQL is not good at string manipulations.

Have separate table which "links" the records: the id of the row you want to associate with the id list, and the id you want to associate it with. So for your string, you would have 13 rows in the association table. It may seem like hard work, but think about it: which is easiest:
1) Removing id "21" from your string without affecting anythign else
Or
2) This:
SQL
DELETE FROM AssociationTable WHERE BaseId=1 AND AssocId = 21
 
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