Click here to Skip to main content
15,867,777 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello every body,
My MS SQL database Info table contains 2 columns

Id Info
1 Raj,30
2 Mac,28
3 John,32

Now i want to update my Info table as

Id Info
1 Raj,30,Black
2 Mac,28,Yellow
3 John,32,Green

So the question is,
Is there any direct method (sql queries / statements) by which i can append black , yellow etc to Info column?
Posted

SQL
UPDATE P1
 SET P1.Info = P1.Info + ',' + 'Black'
FROM IDDetails AS P1
WHERE P1.Id = 1

Repeat update for each Id
 
Share this answer
 
Comments
__TR__ 11-Sep-12 6:52am    
5+
Kuthuparakkal 11-Sep-12 6:53am    
Thanks __TR__ !!!
__TR__ 11-Sep-12 6:56am    
I wonder why was it downvoted.
Kuthuparakkal 11-Sep-12 7:12am    
We have bugs in this community with negative attittude... I have already raised this to CodeProject...
Kuthuparakkal 11-Sep-12 6:57am    
Some miscreant downvoted for no reason... He should have vacuum at Dad's place...
Here is a sample code. Hope this helps

CREATE TABLE #SampleTable
(
	ID INT IDENTITY(1,1),
	Info VARCHAR(100)
)

INSERT INTO #SampleTable
SELECT 'Raj,30' UNION ALL
SELECT 'Mac,28' UNION ALL
SELECT 'John,32'


SELECT * FROM #SampleTable

UPDATE #SampleTable
SET Info = Info + ',Black'
WHERE ID = 1


SELECT * FROM #SampleTable

DROP TABLE #SampleTable
 
Share this answer
 
Comments
Mohamed Mitwalli 11-Sep-12 8:40am    
5+
__TR__ 11-Sep-12 12:15pm    
Thanks Mohamed.
code4Better 12-Sep-12 0:48am    
5+ TR
__TR__ 12-Sep-12 10:19am    
Thank you Sarin :)

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