Solved

How do I update SQL records based on a SQL query

Posted on 2014-02-18
3
273 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
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Creating and Managing Databases with phpMyAdmin in cPanel.
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 to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

757 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

21 Experts available now in Live!

Get 1:1 Help Now