troubleshooting Question

UPDATE statement in SQL

Avatar of Lily
Lily asked on
SQL
8 Comments2 Solutions109 ViewsLast Modified:
i have these  columns as an example:
ID  Line  Mod2, Mod3, Mod4
1    1                     59
1    2                     59    

Here is the result from the SQL script below:                  
                             
ID      LINE #      MOD1      MOD2      MOD3      MOD4
A1      1                              59              59      
A1      2                              59              59      

Line 1:  I need to move the value in Mod3 to Mod2 (if Mod2 is blank) and remove the value in Mod3 - only if the move has happened

same if there is a value in Mod4   (if Mod2 and Mod3 are blank), then move Mod4 to Mod2 and remove value from Mod4

Here is SQL script
SELECT ID, LINE,
CASE WHEN MOD2 = '' THEN COALESCE(MOD3, MOD4) ELSE MOD2 END  as MOD2,
CASE WHEN MOD3 = '' THEN MOD4 ELSE MOD3 END as MOD3 ,
MOD4 = ''
FROM

I actually need to change this to an update statement ...created the SQL select to view the results

If anyone can help out, please let me know.  Thank you
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros