Click here to Skip to main content
11,478,896 members (76,033 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL
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 11-Sep-12 1:42am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

UPDATE P1
 SET P1.Info = P1.Info + ',' + 'Black'
FROM IDDetails AS P1
WHERE P1.Id = 1
Repeat update for each Id
  Permalink  
Comments
__TR__ at 11-Sep-12 6:52am
   
5+
Kuthuparakkal at 11-Sep-12 6:53am
   
Thanks __TR__ !!!
__TR__ at 11-Sep-12 6:56am
   
I wonder why was it downvoted.
Kuthuparakkal at 11-Sep-12 7:12am
   
We have bugs in this community with negative attittude... I have already raised this to CodeProject...
Kuthuparakkal at 11-Sep-12 6:57am
   
Some miscreant downvoted for no reason... He should have vacuum at Dad's place...
sarin from bangalore at 11-Sep-12 7:19am
   
Hello Kuthuparakkal,
Thanks for helping. Great logic and its working fine
Kuthuparakkal at 11-Sep-12 7:21am
   
you're most welcome!
Plz mark answer if it helps!
Mohamed Mitwalli at 11-Sep-12 8:40am
   
5+
Kuthuparakkal at 11-Sep-12 9:08am
   
Thanks Mohammed Mitwalli
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Mohamed Mitwalli at 11-Sep-12 8:40am
   
5+
__TR__ at 11-Sep-12 12:15pm
   
Thanks Mohamed.
sarin from bangalore at 12-Sep-12 0:48am
   
5+ TR
__TR__ at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 200
1 F-ES Sitecore 195
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,880
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100