Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
empId	emp_Name	emp_sal
1	   ram, name	     10000
2	   ramesh	     11000
3	   manish	     12000


update it emp name where id=1

empId	emp_Name	emp_sal
1	        ram, amit	10000
2	         ramesh  	11000
3	          manish	12000


What I have tried:

select empId, emp_Name, emp_sal from emp
Posted
Updated 1-Jan-18 22:55pm
Comments
Karthik_Mahalingam 2-Jan-18 4:48am    
what is your expected output?
Use Improve question to add more info to the question.
GKP1992 2-Jan-18 4:54am    
There is no way SQL server can know which value to update out of the various values separated by commas. You have to do it programmatically and update the whole value.
e.g. Initial Value = ram, name
Logic to determine final value, takes initial value as input
Final value as output of previous logic.
use this value to update row.
update emp set emp_name = "final value" where empId = "id"

1 solution

Simple: Don't use comma separated values in columns.
SQL server is not good at string handling: and storing data as comma separated values always gives you trouble. It's complex, and unnecessarily so.

Instead, use either separate columns (one for first name, one for second name if that's what you are storing) or a second table which interrelates values (if you are storing two employees under the same column and row). You can then use JOIN to combine the data back, and SQL is very good at those!
 
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