Solved

SQL Server Update statement

Posted on 2014-09-23
2
183 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

770 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