SQL HELP [message #307409] |
Tue, 18 March 2008 17:17  |
ravi214u
Messages: 153 Registered: February 2008 Location: CANADA
|
Senior Member |
|
|
hi ,
select n_decrease_exp_amt,CASE WHEN v_pre_post_ind ='Pre' then n_decrease_exp_amt when v_pre_post_ind ='Post'then n_decrease_exp_amt * -1 end Redist,v_pre_post_ind from fct_op;
i wan this output
n_decrease_exp_amt Redistribution v_pre_post_ind
-50 -50 Pre
-25 -25 Pre
0 0 Pre
0 50 Post
0 25 Post
0 0 Post
But i M getting
n_decrease_exp_amt Redistribution v_pre_post_ind
-50 -50 Pre
-25 -25 Pre
0 0 Pre
0 0 Post
0 0 Post
0 0 Post
please help
thanks in advance
|
|
|
Re: SQL HELP [message #307411 is a reply to message #307409] |
Tue, 18 March 2008 17:26   |
 |
Barbara Boehmer
Messages: 9104 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
You need to provide create table and insert statements for the data that your results are based on and explain why the results should be that way, what logic dictates that the 25 and 50 should be 0 instead. Please read the forum guide highlighted in yellow at the top of the forum page for what we expect. 0 times -1 is 0, not 25 or 50, the query is providing what you have asked for.
[Updated on: Tue, 18 March 2008 17:28] Report message to a moderator
|
|
|
Re: SQL HELP [message #307419 is a reply to message #307411] |
Tue, 18 March 2008 18:16   |
ravi214u
Messages: 153 Registered: February 2008 Location: CANADA
|
Senior Member |
|
|
Sorry, i am again explaning it clearly.
Master table
create table VW_FCT_IR
(
N_DECREASE_EXP_AMT NUMBER(22,2),
V_PRE_POST_IND VARCHAR2(5)
);
select * from VW_FCT_IR
N_DECREASE_EXP_AMT V_PRE_POST_IND
-50.00 Pre
-25.00 Pre
0.00 Pre
0.00 Post
0.00 Post
0.00 Post
I have to insert value from master table to the new table as
shown below
The condition is when V_PRE_POST_IND is Pre insert
N_DECREASE_EXP_AMT and when V_PRE_POST_IND is Post
N_DECREASE_EXP_AMT * -1 in same column.
create table FCT_IR
(
N_DECREASE_EXP_AMT NUMBER(22,2),
REDIST NUMBER(22,2),
V_PRE_POST_IND VARCHAR2(5)
);
Required Output:-
N_DECREASE_EXP_AMT Redist V_PRE_POST_IND
-50.00 -50 Pre
-25.00 -25 Pre
0.00 0 Pre
0.00 50 Post
0.00 25 Post
0.00 0 Post
Thanks in advance
[Updated on: Wed, 19 March 2008 00:45] by Moderator Report message to a moderator
|
|
|
|
|
Re: SQL HELP [message #307650 is a reply to message #307511] |
Wed, 19 March 2008 06:16   |
ravi214u
Messages: 153 Registered: February 2008 Location: CANADA
|
Senior Member |
|
|
Hi Michel,
Thanks for replying.
what ever come in pre . the same will come in post with multipling (-1). so that the total will be 0.
|
|
|
|
Re: SQL HELP [message #307671 is a reply to message #307657] |
Wed, 19 March 2008 07:12   |
ravi214u
Messages: 153 Registered: February 2008 Location: CANADA
|
Senior Member |
|
|
Micheal pre and post always remain same .. Bec they have to sum up to zero.
So the case is when V_PRE_POST_IND is Pre insert
N_DECREASE_EXP_AMT in Redist only for those rows where V_PRE_POST_IND ='Pre' and for same column when V_PRE_POST_IND is Post insert
N_DECREASE_EXP_AMT *(-1) into redist where V_PRE_POST_IND is pre and it will update those rows in redist where V_PRE_POST_IND ='Post' .
I thing u will understand with this example.
|
|
|
|
|
|
Re: SQL HELP [message #307680 is a reply to message #307678] |
Wed, 19 March 2008 08:15   |
ravi214u
Messages: 153 Registered: February 2008 Location: CANADA
|
Senior Member |
|
|
ok i will explain again
i have to populate redist.
the condition will be when V_PRE_POST_IND='Pre' insert N_DECREASE_EXP_AMT into redist. only 3 rows will be updated. right
Now same 3 rows will be updated in next 3 rows of same column where the condition is Post but multiplying (-1).
|
|
|
Re: SQL HELP [message #307682 is a reply to message #307680] |
Wed, 19 March 2008 08:21  |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Yes but: "Which "post" is 0? Which "post" is 25? Which "post" is 50?"
Still don't have the answer for this.
Regards
Michel
|
|
|