Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I update SQL records based on a SQL query

Posted on 2014-02-18
3
Medium Priority
?
307 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 66

Accepted Solution

by:
Jim Horn earned 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

715 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