Nickk
Nickk

Reputation: 23

SQL field data addition

I am just wondering if it is possible to do something and as I cannot find any information about it:

let's say I have a field that I want to concatenate values to it:

For example

table 'test'

id |  name            |  surname 
01 |  georges         |  Michael

and I am trying to add information about this field like :

table 'test'

id |  name             |  surname
01 |  georges, rick    |  Michael

Do I need to update, insert or alter this 'test'.'name' with a second value(in this case 'rick')? Is it even possible to do that or will I need to create another related table in order to link 'rick' with 'georges'?

I know that if it is possible I will have to "insert" the comma as well but I do not know how.

Upvotes: 1

Views: 54

Answers (1)

Shoeless
Shoeless

Reputation: 678

SQL Server:

UPDATE test SET name = name + ', Rick' WHERE id = '01'

If you need to pull Rick from another table, you could do something like this:

UPDATE t
SET t.name = t.name + ', ' + o.othername
FROM test t
JOIN othername o ON t.id = o.id
WHERE t.id = '01'

And if you were looking for further posts/info on the topic, I'd suggest googling sql server string concatenation

Upvotes: 1

Related Questions