• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

SQL Update

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
W.E.B
Asked:
W.E.B
  • 3
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Lose the second Updated

Updated = Case WHEN POD = '' THEN  Null ELSE 'YES' END,
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>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
 
David KrollCommented:
Updated = Case when POD = '' THEN  Null Else 'YES' End,
0
 
W.E.BAuthor Commented:
Thank you,
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now