Solved

How do I update SQL records based on a SQL query

Posted on 2014-02-18
3
294 Views
Last Modified: 2014-02-18
I have a bunch of records which returns a NULL value. I'd like to change update all of these so that they have a value.

The table that needs to contains the information is activity_value_users. The field is Department. Based on the query below, how do I update the department field for all records.


select a.activity, a.activity_desc, v.department, AV.activity_value


from activities A



LEFT OUTER JOIN activity_value_users V ON v.activity = a.activity
LEFT OUTER JOIN activity_values AV ON AV.activity = a.activity

where a.activity = 'EX3'

Open in new window



I have also attached the image of what the query brings back.
Screen-Shot-2014-02-18-at-19.32..png
0
Comment
Question by:MSSC_support
[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
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39868371
>I'd like to change update all of these so that they have a value.
Any value in particular?  'Banana', 42, True?

Because it's a LEFT JOIN, ultimately you're going to have to insert rows into DEPARTMENT with a matching value in .activity = 'EX3', and a value in .departement to return to pull this off.
0
 
LVL 8

Expert Comment

by:5teveo
ID: 39868474
Use is null... replace
AV.activity_value
with
ISNULL(AV.activity_value,"THIS VALUE")


select a.activity, a.activity_desc, v.department, ISNULL(AV.activity_value,"THIS VALUE")
from activities A
LEFT OUTER JOIN activity_value_users V ON v.activity = a.activity
LEFT OUTER JOIN activity_values AV ON AV.activity = a.activity
where a.activity = 'EX3'
0
 

Author Closing Comment

by:MSSC_support
ID: 39868690
Got it working with something based off this! Thank you.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

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