sam
sam

Reputation: 19

Updating a column from a SELECT statement

I'm trying to add a new column in my Family table called Full Address. It is basically combining values from other columns and generating the Full Address.

I wrote the below query, but it does not seem to be working. Also, I would appreciate it if there's a better way to generate my desired value- Full Address.

UPDATE Family SET FullAddress = (SELECT StreetAddress+', '+City+', '+State+', '+ZipCode AS Address FROM Family)

Thanks!

Upvotes: 1

Views: 70

Answers (4)

cmnardi
cmnardi

Reputation: 1111

Try

UPDATE Family SET FullAddress = StreetAddress+', '+City+', '+State+', '+ZipCode

Upvotes: 1

Novice
Novice

Reputation: 558

Instead of using SELECT, you may try to use CONCAT in your query:

UPDATE Family SET 
FullAddress = CONCAT(StreetAddress ,', ' City ,', ' STATE ,', ' ZipCode ) AS Address

Upvotes: 1

Shushil Bohara
Shushil Bohara

Reputation: 5656

Keep Gap between the quote if you need more space:

UPDATE Family SET 
FullAddress = CONCAT(StreetAddress, ', ', City, ', ', STATE, ', ', ZipCode)

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269583

Presumably, you just want this:

UPDATE Family
    SET FullAddress = StreetAddress + ', ' + City + ', ' + State + ', ' + ZipCode;

Upvotes: 1

Related Questions