Solved

SQL Server Update statement

Posted on 2014-09-23
2
174 Views
Last Modified: 2014-09-24
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
Comment
Question by:countyprob
2 Comments
 
LVL 15

Assisted Solution

by:Haris Djulic
Haris Djulic earned 250 total points
ID: 40340425
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
 
LVL 1

Accepted Solution

by:
aneesa83 earned 250 total points
ID: 40341255
UPDATE C SET TEXT=TEXT+'PLUSCAT' FROM @B C INNER JOIN @A D ON D.PK_ID=C.ID AND D.EVENT=20
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now