One merge instead of three different
Hi all,
My need is to calculate rows and write result into column:
c1 if current month is 1st in quarter,
c2 if current month is 2nd in quarter,
c3 if current month is 3rd in quarter.
For example, today is August, it's the second month in quarter, so I should write my value into c2 column.
In my example below the result is just one row:
select 111 as id, 1 as c1, 0 as c2, 0 as c3 from dualMy real result is much bigger, so I use merge to insert (is id is new) or to update (if id is already present in table).
The question is how do I perform this using one merge instead of three different. In case it's possible at all, of course.
CREATE TABLE marco_tmp_010811b
(id NUMBER(9,0) PRIMARY KEY,
c1 NUMBER(15,0) NOT NULL,
c2 NUMBER(15,0) NOT NULL,
c3 NUMBER(6,0) NOT NULL);
begin
if months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 0 then
merge into marco_tmp_010811b rr
using
(select 111 as id, 1 as c1, 0 as c2, 0 as c3 from dual) hh
on (hh.id = rr.id)
when matched then update set rr.c1 = rr.c1 + hh.c1
when not matched then insert (rr.id, rr.c1, rr.c2, rr.c3)
values (hh.id, hh.c1, hh.c2, hh.c3);
end if;
if months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 1 then
merge into marco_tmp_010811b rr
using
(select 111 as id, 0 as c1, 1 as c2, 0 as c3 from dual) hh
on (hh.id = rr.id)
when matched then update set rr.c2 = rr.c2 + hh.c2
when not matched then insert (rr.id, rr.c1, rr.c2, rr.c3)
values (hh.id, hh.c1, hh.c2, hh.c3);
end if;
if months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 2 then
merge into marco_tmp_010811b rr
using
(select 111 as id, 0 as c1, 0 as c2, 1 as c3 from dual) hh
on (hh.id = rr.id)
when matched then update set rr.c3 = rr.c3 + hh.c3
when not matched then insert (rr.id, rr.c1, rr.c2, rr.c3)
values (hh.id, hh.c1, hh.c2, hh.c3);
end if;
end;
Can be also like this
begin
merge into marco_tmp_010811b rr
using
select
111 as id,
case when months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 0 then 1 else 0 as c1,
case when months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 1 then 1 else 0 as c2,
case when months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 2 then 1 else 0 as c3
from dual
) hh
on (hh.id = rr.id)
when matched then
update set
rr.c1 =
CASE WHEN months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 0 THEN rr.c1 + hh.c1 ELSE rr.c1 END,
rr.c2 =
CASE WHEN months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 1 THEN rr.c2 + hh.c2 ELSE rr.c2 END,
rr.c3 =
CASE WHEN months_between(trunc(sysdate+125,'MM'),trunc(sysdate+125,'Q')) = 2 THEN rr.c3 + hh.c3 ELSE rr.c3 END
when not matched then
insert (rr.id, rr.c1, rr.c2, rr.c3)
values (hh.id, hh.c1, hh.c2, hh.c3);
end;In different IF conditions, we have to make sure that other column value should not be changing,
So in the else condition of CASE in the UPDATE section we will be using the current value of the column.
Edited by: bpat on Aug 1, 2011 10:23 AM
Similar Messages
-
How do I combine three itune accounts into one? Then how do I set up three users for the one Itunes account on ONE Mac Pro Computer with one Itunes program? We are one family with 3 I-Phones, 2- I-Pads, 2- Lap tops and 3-I-Pods and would like to use one main computer to sync all our devices to.
"How do I combine three itune accounts into one? "
You cannot.
"Then how do I set up three users for the one Itunes account on ONE Mac Pro Computer with one Itunes program?"
You can copy all of the music to one computer and set up different users see:
Learn how to set up additional user accounts.
How to use multiple iPods, iPads, or iPhones with one computer -
How can you get your iPhone videos to compress to one video instead of 5 different frames?
How can you get your iPhone videos to compree to one video instead of different frames
It sounds like you to 5 separate videos. If you start recording, then stop it, then start it again, you will have 2 videos. Not 1. As for splicing them together, you will need a video editing package for your PC. I don't know if Windows Movie Maker (or whatever they're calling it now) can handle this or not. On a Mac, I'd say just use iMovie.
-
Hi,
I am developing a VI in which I need to display three images(two of which are the resulting images after the third one is processed) in three different planes.All these image planes must be at right angles to each other,as the faces of a cube.All these images should be visible at a time.I am looking for some help on this matter and if any one has an idea if this is possible,plz contact me.
maroonerHere is the VI that I tried to use in my measurements. The VI acts very weirdly: it seems to capture a position of one axis at the time when it should capture positions for each axis simultaniously. The axis where the position is captured changes randomly. Like there would be some kind of competition between the buffers. The total amount of captured positions is often 10 which is the size set for each buffer. However, total amount is not always 10 but it can be sometimes less or more. Somehow the buffers stop getting data in the them.
The same trigger pulse is used for each axis. I use a UMI-7764 where I set the triggers to go to Trigger Input Terminal Block. Again, this works fine in one dimension but not with two or three motors.
Please help me,
Adddad
Attachments:
BHSC.vi 83 KB -
SSAS : one dimension instead of 3 times the same
I want to make a cube that show, for each factory, how many units produced and how many units transfered between 2 factories by month.
I have a DimFactory dimension that represents factories.
My 1st fact table (FactProduction) is what have been produced in a factory. So I have a FactoryKey that links my FactProduction to DimFactory.
My 2nd fact table (FactTransfer) is what have been transfered (i.e. shipped) between 2 factories. I have 2 foreign keys: FromFactoryKey and ToFactoryKey.
Both are linking my FactTransfer to DimFactory (so for each record I have a FROM and a TO).
I created a cube that uses both fact tables but of course when I do so, I have to use 3 dimensions (each of them being DimFactory):
Location (FactProduction.FactoryKey -> DimFactory.FactoryKey)
LocationFrom (FactTransfer.FromFactoryKey -> DimFactory.FactoryKey)
LocationTo (FactTransfer.ToFactoryKey -> DimFactory.FactoryKey)
I would like to use only one dimension (Location) and using Calculated Fields I would have 3 measures:
Quantity Produced
Quantity Transfered From
Quantity Transfered To
So for the currentmember in DimFactory I would have 3 columns.
MONTH | FACTORY | Produced | TRF FROM | TRF TO
===============================================================================================
JANUARY NEW YORK 45,600 23,450 12,344
FEBRUARY MIAMI 20,200 12,233 5,673
What kind of calculation I must do to get these measures (and be able to use one DimFactory instead of three)
Thank you for your helpI found a way to do what I was looking for, by splitting my records in half.
So my fact table now has 2 records for each transfer, with only one FactoryKey with a column telling what kind of record it is (TO or FROM).
That way I can have a calculated field saying "if it is a TO, then TRANSFER IN QTY is QTY else TRANSFER IN QTY is 0 and same logic for a FROM"
In my cube I have only one dimension (DimFactory) and for each factory I have 2 columns : TRANSFER IN, TRANSFER OUT. -
With three different objects in one Section with in one report is it possible?
Hi my dear friends, Good morning
I'm using BO 4.1 sp 6
I needed some help from you could you please .........
here is that table contains ....
Date Batch NO Customer account No amount of check amount
01/01/04 5678 123456 $300 $ 500
This report contains three different structures based up on user selection Section
system Name , Batch NO, Company code Used in Section
query filters and column are same for all above three structures in query filters all are optional prompts
currently i've created three tabs for three structures but due to optional prompts based upon selection data is fetching for all three tabs ...
is it possible to restrict ?
can i merge these three tabs into one tab ?
query filters are user selection for System name in Section
class name class name :suspense
class type Date :
system name : User selection for Company Code in Section
Date : Class Name : Suspense , Class Type : Rejected , System name : Mars , Date :
Company code : User selection for Batch No In Section
Class Name : Suspense , Class Type : Rejected , System name : Mars , Date :
End user front end application is Java
Thanks
Ravi Kumarhi friends,
Hi hesters thanks for your help it is helpful but my requirement is not met with that.
i've got answer
create condition @ universe level
with
'System Name'= @Prompt("Subtotal By','A',{'system Name','Batch No','Company Code'},mono,Persistent,)
need to create for what are the objects we are using in section
and create userresponse @ report level
if(Userresponse("Subtotal By") then [System Name] ......
you will get it........... -
I'd like to merge the three different itunes accounts I have created over time ... is this possible?
Unfortunately it is not possible to merge multiple Apple ID's and their content into one ID. Apple has no provisions for this.
-
How do I use three different Iphones on one computer?
I have three different iphones being used in one house. So far only one has ever been uploaded and saved to iTunes on the computer itself. I've been scared to do the other two devices in fear that somehow all of our apps will combine or be lost. None of us have the same apps or music. How do I go about adding the other two phones? PLEASE someone help.
Have a read Here...
https://discussions.apple.com/message/18409815?ac_cid=ha -
When I merge one project with another, Aperture 3 randomly scrambles the photos of the project being merged, instead of keeping them in the chronological order that I shot them in. What can I do to correct this?
The photos have just been dumped into a new home and need to be told how to be arranged. Go to the top left of the browser view for the merged project and select the desired sort order from the drop-down and they'll all sort according to that setting.
-
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
I live in the US, and I will be traveling to The Netherlands, Germany and Luxembourg in May. I will be taking my MacBook Pro, 1st generation iPad and iPhone 4G. Is there a universal charger that I can use with all three devices, as opposed to taking three seperate chargers?
I obviously have three different chargers, I guess my question is, can I use just one of those chargers for all three devices, and if so, which one of the three, or does it matter? And if I can in fact use just one of the three, then why would I need all three in the US? Also, if one of the three will work on all devices, would the automotive charger work the same, one for all? Thank you for your reply.
-
Difficulty wiring three different arrays to one spreadsheet file
I am having trouble outputting three different arrays from a case structure and sending them to an Excel file. I have read through several similar Excel threads and not seen anything really similar to my situation. I can't even get my arrays correctly wired to the "write to file" icon. Any suggestions would be great. I also attached my vi for reference.
Thanks
Attachments:
Read voltage, give current 5-29.vi 38 KBI cleaned it up a bit and fixed a few problems. It may not do everything that you want but I take no credit for the way the cose is written.
Tim
Johnson Controls
Holland Michigan
Attachments:
Read voltage, give current 5-29.vi 24 KB -
I have three different data base regions
Help is Greatly appreciated.
I have three different databases - development, QA and Production.
my requirement --I have to insert 20 new records into "scott.PERMANENT" table
2)In the Developemnt,QA both regions in the "scott.PERMANENT" table , 3 records are already presnet in the above new 20 records. 3)In the Production database , i dont have any data and have to insert all of the records.
So inorder to insert the data i have to use the same script in all the regions meaning i have to iclude all the 20 new records in the insert script ,but based on the region name it should check and insert those records .
could anyone please kindly give me an idea how to check the region name and insert.
Your help is kindly appreciated.Hi,
975482 wrote:
Help is Greatly appreciated.
I have three different databases - development, QA and Production.
my requirement --I have to insert 20 new records into "scott.PERMANENT" table Don't create your own tables in Oracle-supplied schemas, such as SCOTT. Why not create your own schema?
2)In the Developemnt,QA both regions in the "scott.PERMANENT" table , 3 records are already presnet in the above new 20 records. 3)In the Production database , i dont have any data and have to insert all of the records.
So inorder to insert the data i have to use the same script in all the regions meaning i have to iclude all the 20 new records in the insert script ,but based on the region name it should check and insert those records .Use MERGE instead of INSERT. If you're using Oracle 10 or higher, then you don't even need a WHEN MATCHED clause; if you only have a WHEN NOT MATCHED clause, it will simply ignore the rows that you said to add but already exist.
If the columns have unique constraints, you can also INSERT all the data, and use an error logging clause
I hope this answers your question.
If not, post a complete test script that people can run to re-create the problem and test their ideas.
For example:
-- In all 3 databases, the permanent table looks like this:
CREATE TABLE permanent ...
-- In Production, where it has no rows, I could populate it like this:
INSERT INTO permanent ...
-- This is how I want the table to look in all 3 databases when everything is finished.
-- But in Development and QA, the table does have some rows already, like this:
TRUNCATE TABLE permanent;
INSERT INTO permanent ...
-- What statement(s) would get the table to the finished state regardless of how it starts?Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Sales of service materials from one SO or Contract with different durations
Dear Gurus,
I have to make a sales process for some service materials. Yet I could not decided whether I should go for sales order or contract. If contract then which one will be the suitable for my requirement?
Requirement is like,
for example I have a college courses as materials. so student purchased a course for 6 months from the middle of a month say from 16th of Jan and going to continue upto 15 July so I want the Jan invoice for amount of 16 days only. then the invoice of february for 28 days amount only later the 3 invoices for 30 and 31 days month with respective amount and the last invoice in july month will be for 15 month with the completion of the amount of 15 days only. hence the system should distribute the amount per days of the month from the start to end of the course duration.
in the same order/contract i have a second course for same student where sale of a course for 1 year where he has to pay quarterly so the 4 invoices with with respective amount bifurcation are required.
the third material with the 100% advance payment.and only one invoice on the same day of the purchase of course.
can we do this scenario with single sales document?
If yes what shall I go for? which Sales order or contract ?
I think whether we go for sales order or contract we have to maintain different item categories for these three different requirements. which item categories will suit for these requirement?
Can we have such different item categories in one document where some item categories have billing plan and some of them are without the billing plan?
Gurus I am trying hard to get the solution for this problem and expecting your useful suggestion for the same.
Please reply. Thanks in advance.
regards,
SanjayHi Sanjai
Go for Rental contract (slaes document type is MV , item cat is MVN) and do the billing plan is periodic billing
if u want to do billing in day wise, week wise, fortnight, monthy,quarterly,halferly ,yearly to customer , u have to do the following setting go to SPRO go to sd-salesdocuments-contracts-contract data-define rules for determining dates
there u have to determine rule table for determine dates
I Think u r problem will solve
Regards
Chowdary -
I have three different e-mail addresses, and need to receive the incoming e-mails from the three sources into my iPhone (it's presently receiving msgs from only one of them). How do I enable my iPhone to do it? Tks in advance.
Many thanks for your help!
Maybe you are looking for
-
How do I use the location bar to automatically load the top google hit?
I recently re-installed Firefox 3.6.12 and created a new profile because my old one was malfunctioning. Before, when I typed something in the location bar (say "nyt") it would automatically load the first Google hit (so I didn't have to type "nytimes
-
Tried to upgrade the software and my phone crashed...restore does not work
What do I do?! I tried to upgrade and it stopped at the verifing software...it went to the screen with the USB plug and the Itunes icon. When I try to restore it stops at the same point on the preparing to restore and goes to verifing software. What
-
Photoshop elements 11 not changing to area
I am using elements 11. Will not change to another area, such as from effects to graphics. Please help! Bev
-
Hi, I want to configure the smtp in cisco prime for receive alarm message in my account .than ,when i press the test button ,the following message is display. Failed to send mail to primary SMTP server. Please make sure that you save mail configurati
-
12c Plug-in for Postgres After looking at http://apex.oracle.com/pls/apex/f?p=34841:9 Welcome to the Oracle Enterprise Manager Extensibility Exchange! that an official one doesn't exist? Austen