Solved

How do I update SQL records based on a SQL query

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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