Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server Update statement

Posted on 2014-09-23
2
Medium Priority
?
211 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 1000 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

885 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