[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

Insert on Case When

Can someone point me in the right direction..

I am trying to do the following
select distinct
  CASE WHEN 
    (SELECT SUM(ORD) FROM RECINC WHERE IN_ITEM = 'SOME ITEM') 
  = (SELECT sum("tSHIPPING") FROM TRANS where "tITEM" = 'SOME ITEM')
  then (INSERT INTO SHIPPING (
  SDATE,
  REC_WH,
  SHIPPING,
  ITEM)
SELECT
  SHIP_DATE,
  RECEIVER_WAREHOUSE,
  ORD,
  CUSTITEMCODE
FROM WAG
WHERE CUSTITEMCODE = 'SOME ITEM') ELSE 0 END AS "TRUE"
FROM recinc inner join trans on in_item = "tITEM"
GROUP BY IN_ITEM;//

Open in new window

0
futureDBA
Asked:
futureDBA
1 Solution
 
sdstuberCommented:
you can't do what you are trying to do.  That is, you can't execute an insert as part of a select result set.

you could try to so something like this where you make the insert conditional based on the results of the sums
ee.txt
0
 
futureDBAAuthor Commented:
excellent solution. thank you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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