Case in Where
select * from table where rn = case when (rn =>1 and transtype =2) then rn =>1 else rn =1 EndSome please help me with this case statement above. I want a case if for all rn =>1 trans_type is 2(check if it 2 for all rn=>1) then use rn =>1 if trans_type is not 2 then use rn =1. Help me with SQL. Thanks..
This is the SQL where rn is coming from
with CTE AS
SELECT
ROW_NUMBER () OVER (PARTITION BY b.account
order by b.TRANS_DATE ASC,b.trans_type desc ) rn
, b.ACCOUNT
FROM ( UNICA.DSI_SUBS_STOP_START_DRW) b
SELECT
ACCOUNT from CTE where rn=1---- i need a case here
Edited by: varun on May 16, 2011 1:47 PM
try this plz..
with CTE AS
SELECT
ROW_NUMBER () OVER (PARTITION BY b.account
order by b.TRANS_DATE ASC,b.trans_type desc ) rn
, b.ACCOUNT
FROM ( UNICA.DSI_SUBS_STOP_START_DRW) b
SELECT
ACCOUNT from CTE where rn=case when (rn =1 and trans_type =2) then 1 else 1 End;Edited by: user2361373 on May 16, 2011 1:56 PM
Similar Messages
-
Hello to everyone
I have a select like as
select
where (KPMERCE IS NULL AND KSMERCE IS NULL)
UNION
where (KPMERCE IS NOT NULL AND KSMERCE IS NULL AND K_PMERCE = KPMERCE)
UNION
where (KSMERCE IS NOT NULL AND K_PMERCE = KPMERCE AND K_SMERCE = KSMERCE)is possibile create a CASE in where clause, something as, So, i can write a single query,
CASE (in where-clause)
WHEN (KPMERCE IS NULL AND KSMERCE IS NULL)
WHEN (KPMERCE IS NOT NULL AND KSMERCE IS NULL AND K_PMERCE = KPMERCE)
WHEN (KPMERCE IS NOT NULL AND KSMERCE IS NOT NULL AND K_PMERCE = KPMERCE AND K_SMERCE = KSMERCE) so
IF CONDITION IS SATISFYED RETURNs ROWS OTHERWISE NO ROWS
Thanks in advanceIf your select lists are equal, then you can do it like this:
where ( (KPMERCE IS NULL AND KSMERCE IS NULL)
or (KPMERCE IS NOT NULL AND KSMERCE IS NULL AND K_PMERCE = KPMERCE)
or (KSMERCE IS NOT NULL AND K_PMERCE = KPMERCE AND K_SMERCE = KSMERCE)
)Regards,
Rob. -
I want to create an array that goes into a case structure where each element in the array is an individual case and gets done in order. Any ideas, I've been playing with the idea but have had no luck, is this even possible?
Hi,
Please check it out the attached Vi.. Is this you need?
Sasi.
Certified LabVIEW Associate Developer
If you can DREAM it, You can DO it - Walt Disney
Attachments:
Event.vi 11 KB -
I wanna get a UML Case Tools, where can i find one for free or opensource?
Hi, Merry X.Mas!!!
I wanna get a UML Case Tools, where can i find one for free or opensource?
Merry X.Mas!!!Hi,
There is one more tool by name Enterprise Architect which supports UML2.0. A 30days eval copy is available. You can try hands on it. -
IPad Air. The case. Where is the origin of that leather ?
iPad Air. The new case.
Where does the leather comes from ?
What is the origin ?
Which animal ?Cowhide, I would imagine. Were it anything else (exotic) it would surely be advertised/marketed as such.
-
Decode/Case in Where clause
Hello,
We are experiencing an issue with a Select statement that uses Decode in the Where clause. Specifically, it seems to be ignoring a nested Decode and just returning the default value. We have another nested decode that works fine, though.
A member of our team mentioned that he believed there was an issue with using Decode and Case statements inside of a where clause within HTML DB...Is this correct? If it is, is there a workaround? Since the nested Decode works elsewhere in this statement, that doesn't seem right.
My select statement looks like:
SELECT
SUBSTR(OBOB.OBOB_CNAME, 0, 30) d,
OBOB.OBOB_UID r
FROM
ISR_OBOB_OBJECT OBOB,
ISR_OBAF_OBJECT_AFFILIATION OBAF,
ISR.ISR_OBSD_SDR OBSD
WHERE
OBOB.OBOB_UID = OBSD.OBOB_UID AND
OBOB.OBOB_UID = OBAF.OBOB_B_UID AND
/*If Personal radio button is selected, displays all SDRs associated with user.
If All is selected, displays all SDRs associated with IS group selected from drop down list
or every SDR.
OBAF.OBOB_A_UID = DECODE(:P1_DISPLAY_ALL,
'Personal', :F101_APP_USER_UID,
/*This is the decode statement that it seems to ignore. If ALL is selected, the query should see if a group has
has been selected from a drop down list that appears when the ALL button is chosen. If a group is selected
(the item isn't 0), only SDRs for that group should be shown. Otherwise, all SDRs for every group should display.
'ALL', DECODE(:P1_SEARCH_IS_SUPPORT_GROUP, 0, OBAF.OBOB_A_UID, :P1_SEARCH_IS_SUPPORT_GROUP),
OBAF.OBOB_A_UID) AND
/*If Personal radio button is selected, display SDRs where user is the Primary assignee.
OBAF.OBAT_UID = DECODE(:P1_DISPLAY_ALL, 'Personal', (select OBAT_UID from ISR_OBAT_OBJ_AFFIL_TYPE WHERE OBAT_APP_REF = 'SDR_PRIMARY'), OBAF.OBAT_UID) AND
/*If a SDR Status (open, completed, on hold, not started...) is selected, only display the SDRs with that status.
OBSD.KTTR_STATUS_UID = DECODE(:P1_ISR_STATUS_UID, 0, OBSD.KTTR_STATUS_UID, :P1_ISR_STATUS_UID) AND
/*If SDR_History textbox is Null, or Open, Not Started, or On Hold SDR status has been selected, then all SDRs with
a create date between today and 99999 months ago will display. Otherwise, only SDRs with a create date between
today and however many months are in the textbox will display (i.e. Completed SDRs created in the past 6 months.)
MONTHS_BETWEEN(sysdate, OBSD.OBSD_CREATE_DATE) <= DECODE(:P1_SDR_HISTORY, NULL, 99999, DECODE(:P1_ISR_STATUS_UID,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_OPEN'), 99999,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_NOT_STA'), 99999,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_HOLD'), 99999,
:P1_SDR_HISTORY))
/*Alphabetical order
Order by
dWe originally wrote this as a PL/SQL statement that returned a query string since most of the where clause is dependent on items the user may or may not select, but we have moved the query into a multiselect list, which only seems to allow SQL Queries.
Any help or advice would be appreciated.
Thanks,
ScottScott: Did you try running that SQL statement in SQL Workshop in Apex? You can run it as it is, it will popup a window asking you to enter values for the bind variables.
JAC73: I don't think an IN clause doesn't work that way, you need a actual SQL sub-query, not an expression from a DECODE/CASE statement. Search this site for str2tbl and see Tom's excellent discussion at
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:110612348061 -
Can we use Case in Where Clause along with Exists
Hi Everybody,
Can we use Case in the where clause with exists? As i have a requirement in which i have to check whether value exists in 6 views, now depending on some value(gns_type )of select clause i have to attach a paticular exists else the performance dies.
Please go through the query any suggestion appreciated.
Thanks
SELECT count(*)
FROM
(SELECT eah.changed_date,
decode(eua.is_deleted, 'N', decode(eah.alert_type, NULL, 'GN', 'R', 'GAR', 'G', 'GAG', 'Y', 'GAY'), 'Y', decode(eah.alert_type, 'R', 'GDR', 'G', 'GDG', 'Y', 'GDY', NULL, 'GN'), NULL, 'GN') AS
alert_type,
decode(eac.pta_line, 'N', '') ptaline,
eac.exp_type_desc,
eac.supplier_name,
eac.transaction_id,
eah.gns_type,
eac.po_amount,
eac.po_end_date,
eah.notes,
eua.is_deleted,
eac.expenditure_type,
eua.gns_alert_summary_id,
eah.changed_date alert_date,
eua.user_alert_id,
eah.reference_number,
decode(eac.cms_pta_line,'N','',eac.cms_pta_line) cms_pta_line,
cms_po_amount,
cms_po_end_date,
mgns.is_decommitted,
eac.gns_alert_id,
eah.gns_type source_name
FROM xxdl.xxdl_sc_gns_alerts_summary eah,
xxdl.xxdl_sc_gns_detail_alerts eac,
xxdl.xxdl_sc_gns_user_alerts eua,
xxdl.xxdl_sc_manage_gns_master mgns
WHERE eah.gns_alert_summary_id = eac.gns_alert_summary_id
AND eah.gns_alert_summary_id = eua.gns_alert_summary_id
AND eah.transaction_id = eac.transaction_id
AND eah.transaction_id = mgns.transaction_id)
a
WHERE(EXISTS
(SELECT 1
FROM xxdl_sc_mng_gns_pta_req_hc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
OR
EXISTS( SELECT 1
FROM xxdl_sc_mng_gns_pta_inv_hc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
OR
EXISTS(SELECT 1
FROM xxdl_sc_mng_gns_pta_req_sc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
OR
EXISTS(SELECT 1
FROM xxdl_sc_mng_gns_pta_inv_sc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
OR
EXISTS( SELECT 1
FROM xxdl_sc_mng_gns_pta_po_sc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
OR
EXISTS (SELECT 1
FROM xxdl_sc_mng_gns_pta_po_hc_v x
WHERE x.transaction_id = a.transaction_id
AND x.source_name = a.source_name
AND x.project_id = 69309
AND x.task_id = 242528
AND x.award_id = 34694)
AND TRUNC(alert_date) >= TRUNC(add_months(sysdate, -1))
AND TRUNC(alert_date) <= TRUNC(sysdate)
AND is_deleted = 'N'
ORDER BY changed_date DESCyou can do
WHERE
CASE WHEN (something) THEN
CASE WHEN EXISTS (SELECT * from ...) THEN 1 ELSE 0 END
WHEN (something else) THEN
CASE WHEN EXISTS (SELECT * from ...) THEN 1 ELSE 0 END
END = 1Looking at your current query, it looks like all those exist statements could be a lot neater, maybe like:
WHERE (69309,242528,34694) IN
(SELECT project_id,task_id,award_id FROM
(Select project_id,task_id,award_id,transaction_id,source_name
FROM
xxdl_sc_mng_gns_pta_req_hc_v
UNION ALL
Select project_id,task_id,award_id
xxdl_sc_mng_gns_pta_inv_hc_v
...) x
where a.transaction_id = x.transaction_id
and a.source_name = x.source_name
)or put the tuple in the where clause at the bottom -
Using CASE on WHERE clause?
Is it posible to use a CASE on the WHERE clause?
I always used the following syntax on MSSQL
but Oracle aparently doesn't accept it:
SELECT...
WHERE
CASE WHEN keyword IS NOT NULL THEN
CONTAINS(field, keyword) > 0
END AND
CASE WHEN varcode IS NOT NULL THEN
code = varcode
END AND
OTHER STATEMENTSSQL> SELECT
2 COUNT(*) OVER() total,
3 ed_fotos.id AS COD_FOTO,
4 ed_fotos.foto.getwidth()/100 AS VLR_LARGURA,
5 ed_fotos.foto.getheight()/100 AS VLR_ALTURA,
6 ed_fotos.arquivo AS NOM_ARQUIVO,
7 ed_areas.nome AS NOM_REDACAO
8 FROM edt.ed_fotos ed_fotos
9 INNER JOIN edt.ed_areas ed_areas ON
10 ed_areas.id = ed_fotos.redacao_id AND
11 (ed_areas.ind_licenciada <> 'S' OR
12 ed_areas.ind_licenciada IS NULL
13 OR (ed_areas.id IN (SELECT * FROM THE (SELECT CAST(fda_
adm.in_list('') AS fda_adm.mytableType) FROM dual)))
14 )
15 LEFT JOIN edt.ed_creditos_fotos ed_creditos_fotos ON
16 ed_creditos_fotos.foto_id = ed_fotos.id
17 LEFT JOIN edt.ed_itens ed_itens ON
18 ed_itens.foto_id = ed_fotos.id
19 LEFT JOIN edt.ed_edicoes ed_edicoes ON
20 ed_edicoes.id = ed_itens.edicao_id
21 LEFT JOIN edt.vw_dedoc_ccda vw_dedoc_ccda ON
22 vw_dedoc_ccda.num_ccda = ed_fotos.num_ccda_sct AND
23 vw_dedoc_ccda.cod_tipo_documento IN ('B','C','C1','C2')
24 LEFT JOIN fda_adm.vw_lui vw_lui ON
25 vw_lui.foto_id = ed_fotos.id AND
26 vw_lui.cod_tipo_documento IN ('B','C')
27 WHERE
28 CASE WHEN 'BUSH' IS NOT NULL THEN
29 CONTAINS(ed_fotos.detalhe, '{BUSH} within termo
OR {BUSH} within headline OR {BUSH} within desc') > 0
30 END) AND
31 1 = 1
32 GROUP BY
33 ed_fotos.id,
34 ed_fotos.foto.getwidth(),
35 ed_fotos.foto.getheight(),
36 ed_fotos.registro,
37 ed_fotos.arquivo,
38 ed_areas.nome,
39 ed_areas.id
40 ORDER BY
41 ed_fotos.id DESC
42 /
CONTAINS(ed_fotos.detalhe, '{BUSH} within termo
OR {BUSH} within headline OR {BUSH} within desc') > 0
ERRO on line 29:
ORA-00905: missing keyword -
Case with where clause - ORA-00920: Invalid relational operator
Hi All, when I try to run the query below, I get the following error...
ORA-00920: invalid relational operator
00920. 00000 - "invalid relational operator"
*Cause:
*Action:
Error at Line: 16 Column: 5
Does anyone know what's wrong with my query? thanks in advance.
SELECT concat (year,period)
FROM DD_ACTUALS_FACT
WHERE CASE Period
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN '03'
WHEN 'APR' THEN '04'
WHEN 'MAY' THEN '05'
WHEN 'JUN' THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'SEP' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END as "MonthNo"
ORDER BY CONCAT (year,"MonthNo") DESCThe problem is the as "MonthNo" - you can't give an "AS" alias to an expression in a where clause.
You have not actually given any condition, just a set of translations from period into a number.
You also haven't said what you're trying to do.
Perhaps you want:
SELECT concat (year,period)
FROM DD_ACTUALS_FACT
WHERE something
ORDER BY CONCAT (year, CASE Period
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN '03'
WHEN 'APR' THEN '04'
WHEN 'MAY' THEN '05'
WHEN 'JUN' THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'SEP' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END ) DESC -
Hi I have select query which is giving issue saying missing key word in case statement else part please do suggest.
/* Formatted on 2012/11/02 16:19 (Formatter Plus v4.8.8) */
SELECT a.kintana_number, a.crid, a.projectestimateid, a.reasonimpacts
FROM (SELECT p.kintana_number AS kintana_number, cr.crid AS crid,
pe.projectestimateid AS projectestimateid,
l.lookupvalue AS reasonimpacts,
(SELECT COUNT (1)
FROM (SELECT p.projectestimateid
FROM projectestimates p INNER JOIN projectestapplications pa
ON pa.projectestimateid = p.projectestimateid
AND pa.impacted = 1
INNER JOIN applicationsupproviders asp
ON asp.appid = pa.appid
INNER JOIN optionssupportproviders osp
ON osp.providerid = asp.providerid
AND LOWER (TRIM (osp.provider)) = 'ibm - adm'
WHERE asp.providertypeid = 2
OR p.admvendornercid IS NOT NULL
UNION
SELECT p.projectid
FROM project p INNER JOIN impactedgroups ig
ON ig.projectid = p.projectid
AND ig.impacted = 1
INNER JOIN optionsgroups og
ON ig.groupid = og.groupid
WHERE og.ibmtowerid IS NOT NULL)
WHERE projectestimateid = pe.projectestimateid) AS v_count
FROM project p LEFT OUTER JOIN projectestimates pe
ON p.projectid = pe.projectid
INNER JOIN attcr.cr_detail cr ON pe.crid = cr.crid
LEFT OUTER JOIN attcr.cr_detail_reason r ON r.crid = cr.crid
LEFT OUTER JOIN attcr.site_lookup l ON l.lookupid =
r.crreasonid
WHERE (CASE
WHEN v_count = 0
THEN pe.estimatestatusid <> 3
ELSE pe.projectestimateid IN (1, 2, 3)
END
AND pe.crid IS NOT NULL) aWHERE (CASE
WHEN v_count = 0
THEN pe.estimatestatusid <> 3
ELSE pe.projectestimateid IN (1, 2, 3)
END
)You cant use CASE statement like that. Modify your where clause like this.
WHERE (
(v_count = 0 and pe.estimatestatusid != 3) or
(v_count != 0 and pe.projectestimateid IN (1, 2, 3)
) -
Hello to all
I have a table:
VALE_1 VARCHAR2(1) DEFAULT 'S',
VALE_2 VARCHAR2(1) DEFAULT 'S',
VALE_3 VARCHAR2(1) DEFAULT 'S',
VALE_4 VARCHAR2(1) DEFAULT 'S',
VALE_5 VARCHAR2(1) DEFAULT 'S',
VALE_6 VARCHAR2(1) DEFAULT 'S',
VALE_7 VARCHAR2(1) DEFAULT 'S',
VALE_8 VARCHAR2(1) DEFAULT 'S',
VALE_9 VARCHAR2(1) DEFAULT 'S',
VALE_10 VARCHAR2(1) DEFAULT 'S',
VALE_11 VARCHAR2(1) DEFAULT 'S',
VALE_12 VARCHAR2(1) DEFAULT 'S',where the columns VALE_1 to VALE_12 represent the months
How can I create a case in a where, that depending on the month that I give i can check the column for that month (VALE_month) and therefore get or not get those rows?
I'll try to explain better:
for example for a given DATE= 01/10/2012 (10 months, it means October), I can create a single query to check only the column VALE_10 , and can get the row if its value is 'S'
select * from
Check if the column VALE_10 = 'S'
I hope I was clear
thanks in advanceHi,
Rosario Vigilante wrote:
Thanks for your time.
Very true, but it, the table, should be up to 12 rows, because each row(transaction) may have 12 values (VALE_XX): a 'S / N' for each month
(rows number * 12)That's right, so create a new table, populate it with 12 times the number of rows that are in your original table, then drop those columns from the original table.
If you can't change the original table, then you can create a view, that normalizes those columns:
CREATE OR REPLACE VIEW notmalized_x
AS
WITH cntr AS
SELECT LEVEL AS month_num
FROM dual
CONNECT BY LEVEL <= 12
SELECT x.primary_key
, c.month_num
, CASE c.month_num
WHEN 1 THEN x.vale_1
WHEN 2 THEN x.vale_2
WHEN 12 THEN x.vale_12
END AS vale
FROM table_x x
CROSS JOIN cntr c
;You'll notice that the CASE expression in the view is very much like the CASE expression that Solomon suggested.
Then you'll be able to do simple queries ion the vie, like this:
SELECT primary_key
FROM normalized_x
WHERE month_num = EXTRACT (MONTH FROM SYSDATE)
AND vale = 'S'
;If you don't want to create a view, you can make normalized_x a sub-query. -
Silicone Macbook Case (Skin) - Where to buy?
I have been searching everywhere for a soft case (like an iPod skin) for my Macbook. I have seen the decals, skintz, silicone keyboard/trackpad covers, skinit, bestskinsever, etc. I even had the new Speck clear hard case, but it was quite uncomfortable on my wrists and scratched the side of my display. All I am looking for is what is found in these two links:
This is the website - in China
This is a picture
In order to purchase, it appears that you need to be a distributor (minimum purchase of 300-1000!) or you want 1 case with 299 spares...
I have emailed their contact people to no avail. I have checked every site and tried every search I could think of.
Help, please??? Has anyone seen anything like this available for purchase? Thanks so much in advance!!!
(And BTW, my last name is Graham; hence the "Graham Cracker" ID - yes, yes, I know...bad choice...)Silicone is a more or less an insulator. The macbook uses fans as well as the bottom of the case to dissipate heat. My main concern would be heat dissipation - as the silicone covers the entire bottom area of the macbook. Further more - as Bricks322 mentioned - the macbook draws air in throught the keyboard area. Combine the two factors and you got a macbook that's hotter than it already is.
It looks wonderfull - but if you're going to make your notebook suffer from heat - it kinda defeats the purpose. You may end up with scratch free toaster -
i have a problem in decode clause
i have 2 conditions in my code
--condition 1
-- this condition in where clause
where gl.attribute1 is null
and gl.attribute2 is null
-- condition 2
--another condition in where clause is
where gl.attribute1 is not null
and gl.attribute2 is not nulli have a parameter is :p_exception = yes then condition 1 runs otherwise condition 2 runs
please helpCheckout:
SQL> SELECT * FROM t;
A B
1
5
4 5
SQL> variable p_exception varchar2(3);
SQL> exec :p_exception :='Yes';
PL/SQL procedure successfully completed.
SQL> SELECT * FROM t WHERE (:p_exception = 'Yes' AND a IS NULL AND b IS NULL) OR (:p_exception='No' AND a IS NOT NULL AND b IS NOT NULL);
A B
SQL> exec :p_exception :='No';
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1* SELECT * FROM t WHERE (:p_exception = 'Yes' AND a IS NULL AND b IS NULL) OR (:p_exception='No' AND a IS NOT NULL AND b IS NOT NULL)
SQL>
SQL> /
A B
4 5 -
Hi,
I am wondering how to implement case logic where THEN statement would be written only once for many WHEN's.
This example is from the oracle documentation, I extended it a bit.
SELECT cust_last_name,
CASE credit_limit
WHEN 100 THEN 'Low'
WHEN 200 THEN 'Low'
WHEN 5000 THEN 'High'
ELSE 'Medium'
END
FROM customers;
As you see we select 'Low' for both values 100 and 200.
What I am really looking for is something like:
SELECT cust_last_name,
CASE credit_limit
WHEN 100
WHEN 200 THEN 'Low'
WHEN 5000 THEN 'High'
ELSE 'Medium'
END
FROM customers;
OR
SELECT cust_last_name,
CASE credit_limit
WHEN 100 OR 200
THEN 'Low'
WHEN 5000 THEN 'High'
ELSE 'Medium'
END
FROM customers;
But both of selects are not valid in oracle (tested on 10g Rel2)
Maybe it is very simple and I am witting it wrong, or it is working only the way I have to repeat the THEN to every WHEN.
Thanks in advance!
let's say I would like to perform the same stepHello
What about
tylerd@DEV2> SELECT
2 CASE
3 WHEN dummy IN('X','Y','Z') THEN
4 'Dummy is X, Y or Z'
5 WHEN dummy LIKE 'A%' THEN
6 'Dummy is like A'
7 ELSE
8 'Dummy is something else'
9 END
10 FROM
11 dual
12 /
CASEWHENDUMMYIN('X','Y'
Dummy is X, Y or ZTHTH
David -
Hi,
Is it possible to use insert statement in CASE.
For example as follows:
let create a table as
create table DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR number, ENDING_ENTERED_BALANCE_CR number);
select
CASE
WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) total > 0
THEN
INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR) values (total)
WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0
THEN
INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_CR) values (total)
else
NULL
end
from gl_balances
where code_combination_id=109940 and currency_code='GBP';
Any answers will be highly appreciated ....
Thanks,
zaheerI don't think that a conditional insert is really needed in this case. THe only part where the insert differse is the else part of your case statment where no insert should be done. THis can be made into a where clause.
An easy way would be to use a simple INSERT + SELECT statement. Where the value for the dr and cr columns are created by a case or a decode statement.
untested example
insert into XXGL_DECOMPENSATED_BALANCE_TMP
(ENDING_ENTERED_BALANCE_DR, ENDING_ENTERED_BALANCE_CR)
select case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) > 0 then total
else null
end as DR
,case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0 then total
else null
end as CR
from gl_balances
where code_combination_id=109940
and currency_code='GBP'
and (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) is not null -- else part
;The good thing is you could run this insert statement for several code_combination_ids directly in SQL without any pL-loop.
Just noticed that leonard aready posted almost the same solution.
Edited by: Sven W. on Aug 24, 2011 3:22 PM
Maybe you are looking for
-
Please can somebody help? I followed the instructions on the support page for transferring music from computer to another by downloading the music files then putting them into the iTunes music file on the new computer. Unfortunately, iTunes on the ne
-
My Ipod shuffle appears in itunes on mac but not on windows 7 even though we have the latest update of itunes. We have also tried the other solutions on the apple support site.
-
Display description in Overview screens
I am currently working on the Overview Screens for Personal Data, Address etc., and need your inputs on below: 1. how to display the "description" instead of codes/key for the fields like Preferred language(dropdown), Gender (radio button), State (dr
-
Third Party Drop Ship with Auto PO Generation
Hi All - I am using a third party drop ship process and I would like the PO to be automatically generated by the system. I have changed the configuration on the TAS item category and checked 'Create PO Automatically'. I went to OVX5 and maintained t
-
ISA on CRM 5.0 vs 4.0
Everyone, Our company is currently evaluating whether to implement CRM Internet Sales (ISA) on our current platform (CRM 4.0) or to hold off and wait for CRM 5.0 to be released (for us to implement it probably 1+ years). After reviewing the document