Solved

SQL Update

Posted on 2013-01-28
5
290 Views
Last Modified: 2013-01-28
Hello,
can you please help,
the case statement is not working.

if POD column is Empty, then Updated Column is Null else 'YES'

UPDATE DATABASE1.dbo.ScanItem
SET
  POD = DATABASE2.POD,
  PickedUpTime = DATABASE2.PickedUpTime,
  DeliveredTime = DATABASE2.DeliveredTime,
  CCDriverNumber = DATABASE2.PickupDriver,
  Instructions = DATABASE2.Instructions,  
  StatusID = DATABASE2.StatusID,
  ServiceTypeID = DATABASE2.ServiceTypeID,
 Updated = Case when POD = '' THEN  Updated = Null Else 'YES' End,
  OrderDate = DATABASE2.OrderDate
FROM DATABASE2.dbo.ActiveOrders DATABASE2 , DATABASE1.dbo.ScanItem ScanItem
WHERE DATABASE2.OrderNo = ScanItem.CCOrderNo
And DATABASE2.AccountNumber = 3333 and ScanItem.Updated is Null

Any help is appreciated.
0
Comment
Question by:W.E.B
  • 3
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 300 total points
ID: 38826723
Lose the second Updated

Updated = Case WHEN POD = '' THEN  Null ELSE 'YES' END,
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38826734
>FROM DATABASE2.dbo.ActiveOrders DATABASE2 , DATABASE1.dbo.ScanItem ScanItem
btw, I don't see an ON clause that tells SQL how these two tables are joined.
Either this is a cross join, or you need something like..
 
FROM DATABASE2.dbo.ActiveOrders DATABASE2
   JOIN DATABASE1.dbo.ScanItem ScanItem ON DATABASE2.SomeID = ScanItem.SomeID
0
 
LVL 11

Expert Comment

by:David Kroll
ID: 38826742
Updated = Case when POD = '' THEN  Null Else 'YES' End,
0
 

Author Closing Comment

by:W.E.B
ID: 38826752
Thank you,
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38826760
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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