• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

SQL Server Update statement

I'm unsure how to write an update sql server that appends additional value.  I have a table A and table B.  There is column called Text in Table B that needs additional info appended at the end If the table A Event column has value of 20.    

Here is what the tables look like:
 
 My 2 tables look like this
What I want to do is keep the existing text value (in table B column Text)  and add  the verbage "plus cat" if the Table A Event  column has value of 20.  For example add "plus cat" to Text column to say "mouse2 plus cat"  for all Table A records that have Event code 20.  When I join the tables, this is what my results should look like:

After the changes are made the joins look like this
 

thanks
np
0
countyprob
Asked:
countyprob
2 Solutions
 
Haris DulicCommented:
here is the code:

update table_b
set text=text + ' plus cat'
where id in (select id from table_a where event=20)

Open in new window

0
 
aneesa83Commented:
UPDATE C SET TEXT=TEXT+'PLUSCAT' FROM @B C INNER JOIN @A D ON D.PK_ID=C.ID AND D.EVENT=20
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now