Solved

How do I update SQL records based on a SQL query

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

770 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