Solved

SQL Server Update statement

Posted on 2014-09-23
2
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

734 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