Case when then not working
In my database, two variable ID and time (varchar2) are there. I want to populate another variable using case when then by putting below conditon to convert like this
But its not working. Can anyone help me
if time =1 day then '1 Day'
time > 2 days and time <=7 days then '2 to 7 days'
time > 8 days and time <=15 days then '8 to 15 days'
else 'not matching'
ID Time
12 1 days
23 244 days
12 2 days
14 4 days
15 6 days
17 9 days
select time,
case WHEN
UPPER(Time) = '1 DAY'
THEN
'1 day'
WHEN
UPPER(Time) Between '2 DAYS' and '7 DAYS'
THEN
'2 to 7 days'
WHEN
UPPER(Time) Between '8 DAYS' and '15 DAYS'
THEN
'8 to 15 days'
ELSE
'Not matching'
END "update time"
from table1
900487 wrote:
In my database, two variable ID and time (varchar2) are there. If you are storing Days in a column store it as NUMBER or INTERVAL data type. The way you have stored the value looks incorrect.
What you can do is extract the number portion of your time column and apply the CASE statement. Something like this
SQL> with t
2 as
3 (
4 select 12 id, '1 days' time1 from dual union all
5 select 23 id, '244 days' time1 from dual union all
6 select 12 id, '2 days' time1 from dual union all
7 select 14 id, '4 days' time1 from dual union all
8 select 15 id, '6 days' time1 from dual union all
9 select 17 id, '9 days' time1 from dual
10 )
11 select id,
12 time1,
13 case when time1 = 1 then '1 day'
14 when time1 between 2 and 7 then '2 to 7 days'
15 when time1 between 8 and 15 then '8 to 15 days'
16 else 'not matching'
17 end "update time"
18 from (
19 select id, to_number(regexp_substr(time1, '^[[:digit:]]*')) time1
20 from t
21 )
22 /
ID TIME1 update time
12 1 1 day
23 244 not matching
12 2 2 to 7 days
14 4 2 to 7 days
15 6 2 to 7 days
17 9 8 to 15 days
6 rows selected.
Similar Messages
-
Case when statement not working
hi there, I am trying to work out how to get my case statement to work.
I have got the following code.
select pthproto.pthdbo.cnarole.tpkcnarole, pthproto.pthdbo.cnaidta.formataddr as formataddr, cnaidta.dateeffect as maxdate, isnull(cast (pthproto.pthdbo.cnaaddr.prefix1key as varchar (50)),'') + ' ' + isnull(cast (pthproto.pthdbo.cnaaddr.prefix2key
as varchar (50)),'')+ ' ' + isnull(cast (pthproto.pthdbo.cnaaddr.prefix3key as varchar (50)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.houseidkey as varchar (100)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.component1
as varchar (100)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.component2 as varchar (100)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.component3 as varchar (100)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.component4
as varchar (100)),'') + ' ' + isnull (cast (pthproto.pthdbo.cnaaddr.component5 as varchar (100)),'') as mailaddress, row_number() over(partition by pthproto.pthdbo.cnarole.tpkcnarole order by cnaidta.dateeffect desc) as rn into #address from pthproto.pthdbo.cnarole
inner join pthproto.pthdbo.cnaidty on cnarole.tfkcnaidty =cnaidty.tpkcnaidty inner join pthproto.pthdbo.cnaidta on cnaidty.tpkcnaidty = cnaidta.tfkcnaidty inner join pthproto.pthdbo.cnaaddr on cnaidta.tfkcnaaddr = cnaaddr.tpkcnaaddr order by cnaidta.dateeffect
select *, case when mailaddress is not null then mailaddress else formataddr end as test from #address where tpkcnarole = '18306695'
The case when statement is struggling with how i have created the column mailaddress. As it does seem to understand when it is null. In the example I have got there is no value in any of the columns to create
the mailaddress. Hence why I am referencing it from elsewhere. Due to having a way on the system where it picks up data from 2 different places. The mailaddress is always correct if there is one, hence why
trying to reference that one first. So how do i change this case when statement to work ?It's ok I have fixed my own problem
when
(mailaddress
is
null
or mailaddress
=
then formataddr
else mailaddress
end
as test
case -
CASE Statement is not working Derived table
Hi All,
in the bello SQL Statement case statement is not working in derived table. I am new to creation of derived table if any body knows plz kinldy help me out on this.
SELECT x.market, x.droprate as med1
FROM
(select upper(market_name) as market, fulldate as date_value,
(sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
nullif(sum(CASE WHEN (month(BBHDLY.FullDate)}>= 6 and { year(BBHDLY.FullDate)} = 2011) or {fn year(IDENSLABBHDLY.FullDate)} > 2011
THEN BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
from BBHDLY sla
inner join Dim mkt
on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
where fulldate >= GETDATE()-46
group by market_name, fulldate) x,
(select market_name as market, fulldate as date_value,
(sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
nullif(sum(CASE WHEN ({fn month(BBHDLY.FullDate)}>= 6 and {fn year(BBHDLY.FullDate)} = 2011) or {fn year(BBHDLY.FullDate)} >
2011 THEN BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
from BBHDLY sla
inner join Dim mkt
on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
where fulldate >=GETDATE()-46
group by market_name, fulldate) y
where x.market = y.market
GROUP BY x.droprate, x.market
HAVING
SUM(CASE WHEN y.droprate <= x.droprate
THEN 1 ELSE 0 END)>=(COUNT(*)+1)/2 AND
SUM(CASE WHEN y.droprate >= x.droprate
THEN 1 ELSE 0 END)>=(COUNT(*)/2)+1
ThanksIt looks like SQL Server or Sybase given that you're using getdate().
As such, Vinesh's comment to use decode is wrong - decode is Oracle syntax.
Looking at your statement again, I've noticed the following:
you have no { to match the first } - not sure why you're using them anyway.
you haven't given x.market a name - use x.market as market instead
use coalesce instead of nullif if you're on SQL Server. -
Hello everyone,
We have a function return Y or N.
We have 2 table YTable YT and NTable NT.
We are using UNION now.
SELECT ONE.CL1
FROM (
SELECT CL1Y FROM YTable WHERE FUNCTION = 'Y'
UNION
SELECT CL1N FROM NTable WHERE FUNCTION = 'N') ONEWe are wondering to use CASE, WHEN, THEN, END.
Is it possible or NOT?
If you have a chance, please share your experiences.
Thanks in advance,
NY
P.S.
If you have more questions, please let us know.
Edited by: New Yorker on Aug 31, 2010 10:08 AMNew Yorker,
According to the given SQL block, the case function can not be used. You can use the case function with multiple table joins but you can only use the CASE WHEN ELSE END block for one column.
If i got your question correct, that is my answer to your question.
Regards.
Ogan -
My shuffle will play for awhile , then blink red lights and then not work?!
hey
so...my ipod shuffle is werid.
I didn't use it for awhile because I couldn't find it ( my fault ;p)
then when I found it , I charged it and it would work fine, then all of a sudden it would blink red on and off really quickly then not work at all! Then I charged it again and it would work fine. That's not normal..is it?
Help pleasetry restoring it on your computer before using it again
-
Case-when-then logic in join condition
Is it possible to implement case when then logic in join condition?
Instead of:
INGRP1.COL1 = INGRP2.COL1 (+)
something like:
case
when INGRP1.COL2 IS NULL
then INGRP1.COL1 = INGRP2.COL1 (+)
else INGRP1.COL3 = INGRP2.COL3 (+)
end
expression builder for join condition.
Any help much appreciated.Hi Kaiser,
this is my variant
1) join first table with second table twice (define two input group in join, include second table in mapping twice and map them to appropriate join group)
INGRP1.COL1=INGRP2.COL1(+) and INGRP1.COL3=INGRP3.COL3(+)
2) after join calculate attributes from second table with expression like
case when COL2 IS NULL the INGRP2_ATTR else INGRP3_ATTR end
Maybe anyone has a better solution...
Regards,
Oleg -
Upper case "s" does not work in most programs
Upper case "s" does not work in a number of programs, lower case is fine. It is the only letter that is missing in both cases.
Any ideas. Do I need to reinstall driver for keyboard? If so any idea where to get it.Open the Speech pane of System Preferences and check whether either the listening key or the speech key has become set to that keystroke; if so, change the setting.
(41135) -
My nested CASE WHEN THEN ELSE is not working.
I'm working on a report that will provide a status on a component based on a defined Matrix. The status to report is determined in a hierarchal fashion...the highest seqence number status existing is reported.
I've capped the sequence number at 10 (@SeqNumCap_sav)
The matrix table is defined as such:
CREATE TABLE [dbo].[tblAssyLineComponentStatusMatrix](
[MatrixAssyLine] [char](1) NOT NULL,
[MatrixComponentProduct] [char](15) NOT NULL,
[MatrixComponentStatusSequence] [decimal](3, 0) NOT NULL,
[MatrixComponentStatus] [char](3) NOT NULL,
[MatrixStatusDescription] [nvarchar](100) NOT NULL,
[MatrixReportedDescription1] [nvarchar](50) NOT NULL,
[MatrixReportedDescription2] [nvarchar](50) NULL,
[MatrixReportedDescription3] [nvarchar](50) NULL,
[MatrixReportedDescription4] [nvarchar](50) NULL,
[MatrixReportedDescription5] [nvarchar](50) NULL
) ON [PRIMARY]
This is a sample of the tblAssyLineComponentStatusMatrix data:
MatrixAssyLine MatrixComponentProduct MatrixComponentStatusSequence MatrixComponentStatus MatrixStatusDescription MatrixReportedDescription1 MatrixReportedDescription2 MatrixReportedDescription3 MatrixReportedDescription4 MatrixReportedDescription5
E Mast/PullRod 1 W The part has been stamped or welded. Class3PullRods NULL NULL NULL NULL
E Mast/PullRod 2 P The part has been clicked off in a paint hang station. TSMastPaintHang NULL NULL NULL NULL
E Mast/PullRod 3 Y The part has been clicked off in paint pulldown. TSMastPaintUnload NULL NULL NULL NULL
the tblProductionControlComponentReporting is defined as:
CREATE TABLE [dbo].[tblProductionControlComponentReporting](
[WorkUnit] [nvarchar](15) NOT NULL,
[Description] [nvarchar](50) NOT NULL,
[Completed] [datetime] NOT NULL,
[UserID] [nvarchar](30) NULL,
[StationID] [nvarchar](30) NULL,
[Undo] [bit] NULL,
[CompletedUndo] [datetime] NULL,
[UserIDUndo] [nvarchar](30) NULL,
[StationIDUndo] [nvarchar](30) NULL,
[ComponentPartNo] [varchar](15) NULL,
[ComponentClass] [varchar](3) NULL,
[ComponentQty] [decimal](6, 2) NULL,
[ComponentScheduleDate] [datetime] NULL,
[ComponentScheduleShift] [decimal](1, 0) NULL,
[ComponentScheduleWorkunitSequence] [int] NULL,
[ComponentComment] [varchar](200) NULL
) ON [PRIMARY]
A sample of the tblProductionControlComponentreporting data:
assyline WorkUnit Description Completed UserID StationID
E 639422 Class3PullRods 2014-09-15 13:15:44.607 GLOBAL\agmesusr ag2100156
E 639422 Class3PullRods 2014-09-15 13:15:44.607 GLOBAL\agmesusr ag2100156
E 639422 TSFrameFabDeliver 2014-09-25 11:31:44.380 NULL MCA
E 639422 TSMastPaintHang 2014-09-25 22:56:43.740 009932 AG2100294
The problem is that the below code is returning multple records which is causing an error ... if I resequence the above Matrix table data where #3 becomes #10, 2 becomes #9 and 1 becomes #8, the query works fine - but this approach doesn't allow for easy
expansion of the data. Can anyone help me see the problem here?
use eschedule
declare @Workunit varchar(max)
declare @SeqNumCap_sav dec(3, 0)
set @WorkUnit='639422'
set @SeqNumCap_sav= (select top 1 SequenceValueCap from tblAssyLineComponentStatusMatrix_SequenceCap order by SequenceValueCap)
select
Mast_PullRodStatus = case
--Seq 10 Mast/PullRod Component Status
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix where MatrixComponentProduct='Mast/PullRod' and MatrixComponentStatusSequence=@SeqNumCap_sav and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then
(select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=@SeqNumCap_sav
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 9 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-1)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-1)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 8 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-2)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-2)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 7 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-3)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-3)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 6 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-4)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-4)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 5 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-5)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-5)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 4 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-6)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-6)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 3 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-7)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-7)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
--Seq 2 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-8)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod' and MatrixComponentStatusSequence=(@SeqNumCap_sav-8))
--Seq 1 Mast/PullRod Component Status
else case
when (select top 1 [description] from tblproductioncontrolcomponentreporting
where ([description] = (select MatrixReportedDescription1 from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-9)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))))
and Workunit=@WorkUnit
--and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit))
) is not null
then (select MatrixComponentStatus from tblAssyLineComponentStatusMatrix
where MatrixComponentProduct='Mast/PullRod'
and MatrixComponentStatusSequence=(@SeqNumCap_sav-9)
and (MatrixAssyLine=(select assyline from tblProductionControlHeader h where h.workunit=@WorkUnit)))
else ' '
end
end
end
end
end
end
end
end
end
end
Assume Assyline='E'
Eva LeggettGood job posting the DDL.
Your example data should be in a table format though.
DECLARE @tblAssyLineComponentStatusMatrix TABLE (MatrixAssyLine char(1) NOT NULL, MatrixComponentProduct char(15) NOT NULL, MatrixComponentStatusSequence decimal(3, 0) NOT NULL, MatrixComponentStatus char(3) NOT NULL, MatrixStatusDescription nvarchar(100) NOT NULL, MatrixReportedDescription1 nvarchar(50) NOT NULL, MatrixReportedDescription2 nvarchar(50) NULL, MatrixReportedDescription3 nvarchar(50) NULL, MatrixReportedDescription4 nvarchar(50) NULL, MatrixReportedDescription5 nvarchar(50) NULL)
INSERT INTO @tblAssyLineComponentStatusMatrix (MatrixAssyLine, MatrixComponentProduct, MatrixComponentStatusSequence, MatrixComponentStatus, MatrixStatusDescription, MatrixReportedDescription1, MatrixReportedDescription2, MatrixReportedDescription3, MatrixReportedDescription4, MatrixReportedDescription5) VALUES ('E' ,'Mast/PullRod' ,1 ,'W' ,'The part has been stamped or welded. ','Class3PullRods ' ,NULL, NULL, NULL, NULL)
INSERT INTO @tblAssyLineComponentStatusMatrix (MatrixAssyLine, MatrixComponentProduct, MatrixComponentStatusSequence, MatrixComponentStatus, MatrixStatusDescription, MatrixReportedDescription1, MatrixReportedDescription2, MatrixReportedDescription3, MatrixReportedDescription4, MatrixReportedDescription5) VALUES ('E' ,'Mast/PullRod' ,2 ,'P' ,'The part has been clicked off in a paint hang station. ','TSMastPaintHang ' ,NULL, NULL, NULL, NULL)
INSERT INTO @tblAssyLineComponentStatusMatrix (MatrixAssyLine, MatrixComponentProduct, MatrixComponentStatusSequence, MatrixComponentStatus, MatrixStatusDescription, MatrixReportedDescription1, MatrixReportedDescription2, MatrixReportedDescription3, MatrixReportedDescription4, MatrixReportedDescription5) VALUES ('E' ,'Mast/PullRod' ,3 ,'Y' ,'The part has been clicked off in paint pulldown. ','TSMastPaintUnload ' ,NULL, NULL, NULL, NULL)
DECLARE @tblProductionControlComponentReporting TABLE (WorkUnit nvarchar(15) NOT NULL, Description nvarchar(50) NOT NULL, Completed datetime NOT NULL, UserID nvarchar(30) NULL, StationID nvarchar(30) NULL, Undo bit NULL, CompletedUndo datetime NULL, UserIDUndo nvarchar(30) NULL, StationIDUndo nvarchar(30) NULL, ComponentPartNo varchar(15) NULL, ComponentClass varchar(3) NULL, ComponentQty decimal(6, 2) NULL, ComponentScheduleDate datetime NULL, ComponentScheduleShift decimal(1, 0) NULL, ComponentScheduleWorkunitSequence int NULL, ComponentComment varchar(200) NULL)
INSERT INTO @tblProductionCOntrolComponentReporting (WorkUnit, Description, Completed, UserID, StationID) VALUES (639422, 'Class3PullRods', '2014-09-15 13:15:44.607', 'GLOBAL\agmesusr', 'ag2100156')
INSERT INTO @tblProductionCOntrolComponentReporting (WorkUnit, Description, Completed, UserID, StationID) VALUES (639422, 'Class3PullRods', '2014-09-15 13:15:44.607', 'GLOBAL\agmesusr', 'ag2100156')
INSERT INTO @tblProductionCOntrolComponentReporting (WorkUnit, Description, Completed, UserID, StationID) VALUES (639422, 'TSFrameFabDeliver', '2014-09-25 11:31:44.380', NULL, 'MCA')
INSERT INTO @tblProductionCOntrolComponentReporting (WorkUnit, Description, Completed, UserID, StationID) VALUES (639422, 'TSMastPaintHang', '2014-09-25 22:56:43.740', '009932', 'AG2100294')
Your code is a mess, it would take longer to untangle it that it would to solve your problem.
Can you give us an expected output, and perhaps the rules governing what your case statement should be doing? -
Using CASE WHEN THEN in dynamic Region Source area
Hi all,
I've been knocking my head around on this one for a while. Hope someone can show me some guidance. So far, the SQL Query in the Region Source works ok except after the THEN ''||'LINK'||'' . All text between the single quotes displays, and not just the hyperlink LINK. (My goal is to this simple test working, then go back an substitute in APP_ID, Page#, SESSION variables.) But I'm stuck with this problem. Searched the forum but this is as far as I got. Below is the code I'm using in the Region Source area. Perhaps a region attribute setting is needed but I'm unsure. Thanks for any assistance. -Mike
select DISTINCT
AWARD,
CASE
WHEN WINNER_NAME = 'India Retail Support Team'
THEN '<A HREF="http://www.hotmail.com">'||'LINK'||'</A>' *----------------HREF link (LINK) is working fine here but doesn't work ok in Region Source.
ELSE WINNER_NAME
END WN,
GBU_WINNER,
DORDER
from GBUSERVICEPACESETTERAWARDS
where FY = '2012'
and TYPE = 'Service Award'>
As previously requested, please update your forum profile with a real handle instead of "user10734329".
I've been knocking my head around on this one for a while. Hope someone can show me some guidance. So far, the SQL Query in the Region Source works ok except after the THEN ''||'LINK'||'' . All text between the single quotes displays, and not just the hyperlink LINK.Not clear from this what the problem is. It appears to me that LINK is all of the "text between the single quotes". What do you mean by "all text"? (An example on apex.oracle.com is a good way to resolve such ambiguities...)
The usual cause of unexpected results when the separation of concerns is breached and HTML is directly generated in report queries is having the Display Text As report column attribute wrongly set. Ensure it is Standard Report Column rather than the default Display as Text (escape special characters). -
Case statement insert not working
This cursor is retrieving data for each pidm
SPRIDEN_PIDM ACTIVITY1 ACTIVITY2 ACTIVITY3 ACTIVITY4 ACTIVITY5 ACTIVITY6
2287953 RA RC RF RJ RN RU
CURSOR activities_cursor
IS
SELECT spriden_pidm,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
1
) activity1,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
2
) activity2,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
3
) activity3,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
4
) activity4,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
5
) activity5,
REGEXP_SUBSTR (szcasup_activities,
'[[:alpha:]]+',
1,
6
) activity6
FROM saturn_midd.szcasup, saturn.spriden
WHERE szcasup_common_appl_id = spriden_id
AND spriden_ntyp_code = 'CAPP';Then I fetched the results in variadles
FETCH activities_cursor
INTO v_pidm, v_activity1, v_activity2, v_activity3, v_activity4,
v_activity5,v_activity6;
Created a loop with a case statement
LOOP
FETCH activities_cursor
INTO v_pidm, v_activity1, v_activity2, v_activity3, v_activity4,
v_activity5,v_activity6;
EXIT WHEN activities_cursor%NOTFOUND;
IF activities_cursor%FOUND
THEN
CASE
WHEN (v_activity1 IS NOT NULL)
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity1,
sysdate
WHEN (v_activity2 IS NOT NULL)
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity2,
sysdate
WHEN (v_activity3 IS NOT NULL)
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity3,
sysdate
WHEN (v_activity4 IS NOT NULL)
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity4,
sysdate
END CASE;
END IF;
END LOOP;
It is working just for one activity (activity1) The variable definition is correctv_activity1 sorints.sorints_ints_code%TYPE;
v_activity2 sorints.sorints_ints_code%TYPE;
v_activity3 sorints.sorints_ints_code%TYPE;
v_activity4 sorints.sorints_ints_code%TYPE;
v_activity5 sorints.sorints_ints_code%TYPE;
v_activity6 sorints.sorints_ints_code%TYPE;
Edited by: peace4all on Aug 16, 2009 9:42 AMpeace4all wrote:
It is working just for one activity (activity1) The variable definition is correct
Well, what else did you expect? CASE evaluates brances starting first one. If WHEN condition is not met it continues to next one. As soon as WHEN condition is met, THEN clause is executed after that CASE exits. You need to use IF statement, not case:
with t as (
select to_date('01/11/2005','dd/mm/yyyy') Start_Date,to_date('13/11/2005','dd/mm/yyyy') End_Date,13 Days,'CMP1' Component,1000.00 Amount from dual union all
select to_date('01/11/2005','dd/mm/yyyy'),to_date('13/11/2005','dd/mm/yyyy'),13,'CMP2',826.67 from dual union all
select to_date('15/11/2005','dd/mm/yyyy'),to_date('20/11/2005','dd/mm/yyyy'),6,'CMP1',413.33 from dual union all
select to_date('15/11/2005','dd/mm/yyyy'),to_date('20/11/2005','dd/mm/yyyy'),6,'CMP2',166.67 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP1',633.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP2',111.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP3',22.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP4',333.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP1',2480.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP2',1488.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP3',496.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP4',200.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2005','dd/mm/yyyy'),16,'CMP1',522.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2005','dd/mm/yyyy'),16,'CMP2',166.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2005','dd/mm/yyyy'),16,'CMP3',242.00 from dual
SELECT P_Month,
SUM(LEAST(LAST_DAY(P_Month),end_date) - GREATEST(P_Month,start_date) + 1) Total_Days
FROM t,
SELECT ADD_MONTHS(first_month,LEVEL - 1) P_Month
FROM (
SELECT TRUNC(MIN(start_date),'MM') first_month,
TRUNC(MAX(end_date),'MM') last_month
FROM t
CONNECT BY LEVEL <= MONTHS_BETWEEN(last_month,first_month) + 1
WHERE P_Month BETWEEN TRUNC(start_date,'MM') and end_date
GROUP BY P_Month
ORDER BY P_Month
with t as (
select to_date('01/11/2005','dd/mm/yyyy') Start_Date,to_date('13/11/2005','dd/mm/yyyy') End_Date,13 Days,'CMP1' Component,1000.00 Amount from dual union all
select to_date('01/11/2005','dd/mm/yyyy'),to_date('13/11/2005','dd/mm/yyyy'),13,'CMP2',826.67 from dual union all
select to_date('15/11/2005','dd/mm/yyyy'),to_date('20/11/2005','dd/mm/yyyy'),6,'CMP1',413.33 from dual union all
select to_date('15/11/2005','dd/mm/yyyy'),to_date('20/11/2005','dd/mm/yyyy'),6,'CMP2',166.67 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP1',633.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP2',111.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP3',22.00 from dual union all
select to_date('21/11/2005','dd/mm/yyyy'),to_date('28/11/2005','dd/mm/yyyy'),8,'CMP4',333.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP1',2480.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP2',1488.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP3',496.00 from dual union all
select to_date('01/12/2005','dd/mm/yyyy'),to_date('15/12/2005','dd/mm/yyyy'),15,'CMP4',200.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2005','dd/mm/yyyy'),16,'CMP1',522.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2005','dd/mm/yyyy'),16,'CMP2',166.00 from dual union all
select to_date('16/12/2005','dd/mm/yyyy'),to_date('31/12/2006','dd/mm/yyyy'),381,'CMP3',242.00 from dual
SELECT P_Month,
SUM(LEAST(LAST_DAY(P_Month),end_date) - GREATEST(P_Month,start_date) + 1) Total_Days
FROM t,
SELECT ADD_MONTHS(first_month,LEVEL - 1) P_Month
FROM (
SELECT TRUNC(MIN(start_date),'MM') first_month,
TRUNC(MAX(end_date),'MM') last_month
FROM t
CONNECT BY LEVEL <= MONTHS_BETWEEN(last_month,first_month) + 1
WHERE P_Month BETWEEN TRUNC(start_date,'MM') and end_date
GROUP BY P_Month
ORDER BY P_Month
LOOP
FETCH activities_cursor
INTO v_pidm, v_activity1, v_activity2, v_activity3, v_activity4,
v_activity5,v_activity6;
EXIT WHEN activities_cursor%NOTFOUND;
IF v_activity1 IS NOT NULL
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity1,
sysdate
ELSIF v_activity2 IS NOT NULL
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity2,
sysdate
ELSIF v_activity3 IS NOT NULL
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity3,
sysdate
ELSIF v_activity4 IS NOT NULL
THEN
INSERT INTO saturn.sorints
(sorints_pidm, sorints_ints_code,
sorints_activity_date)
values
v_pidm,
v_activity4,
sysdate
END IF;
END LOOP;SY. -
Compaq 610 Keyboard working then not working and so in circle
Greetings to all good members of this forum .
will, one strange thing, when i turn on my laptop all keys will work perfect, then after 3...5 minutes only navigation keys will work. in that case i would restart the laptop, so again it will work. But also it happens even if i restart him it will not work till next restart :s
wondering is it up to keyboard or something with my motherboard. ot I doubt that is up to software problem? Hope there will be some solutio for this, thanks.
This question was solved.
View Solution.Hello saledigitalac,
What is your product number and operating system?
Thanks!
↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓ -
NOT IN clause in CASE statement condition not working
Dear Friends,
I want to use below condition in WHERE clause of my SELECT statement.
WHERE <...........>
<...........>
AND eihf.exr_aip_asset_sid NOT IN
(CASE when safa.fund_relation = 'C' and safa.fund_account_code != vFundAccount
THEN (37874,37909,43424,55040,59513,59598,58570,76148,75885,75927)
ELSE
(0)
END
But it gives me an error as "missing right parenthis".
Please help.
Regards,
JigneshCASE returns one and only one value. It can't return a list. Your satement should be something like:
WHERE <...........>
<...........>
AND (
safa.fund_relation = 'C'
AND
safa.fund_account_code != vFundAccount
AND
eihf.exr_aip_asset_sid NOT IN (37874,37909,43424,55040,59513,59598,58570,76148,75885,75927)
OR
NOT (
safa.fund_relation = 'C'
AND
safa.fund_account_code != vFundAccount
AND
eihf.exr_aip_asset_sid != 0
)SY. -
Hi,
I want to use the CASE function in a sql statement used at form level but it's not working. I can't compile the form. I am using developer 6i at font end and Oracle 10g database at back end. Is it possible to use case function at form level sql statement. If so then please help me about it.
Best RegardsForms has it's own PL/SQL engine, and in Forms 6i it's version 8 where no CASE was available. So if you want to use CASE you'll have to use a view or put your logic in a stored procedure.
-
HI,
my when function is not working fine.
IF E1EDP20 is existing then
text = everything OK
else
text = not confirmed
if there are only lines with E1EDP20 missing or existing then the functions is working fine but if the lines are different E1EDP01/E1EDP20 is missing and another line E1DP01/E1EDP20 is existing then the function uses text = everything OK.
Is that an kontext issue ?
<xsl:for-each select="ORDERS05/IDOC/E1EDP01">
<xsl:choose>
<xsl:choose>
<xsl:when test="string-length(//E1EDP20)=0">
<div valign="top" align="top" class="event" style="color: #ff0000">
<xsl:text>not confirmed</xsl:text>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:text>everything OK</xsl:text>
</xsl:otherwise>
</xsl:choose>
2. How can is use the text color "Red" without using the div function ?
Message was edited by:
Gordon BreuerHi Gordon,
check out
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<output>
<xsl:for-each select="//E1EDP01">
<xsl:choose>
<xsl:when test="count(E1EDP20)!=0">everything ok</xsl:when>
<xsl:otherwise>not confirmed</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
It is not easy to find out what you like to have as result. Imagine: People in XI forum dont know your daily work...
Regards,
Udo -
What to do when iCloud not working ?, what to do when iCloud not working ?
First to begin - I am a big iCloud fan. When it's working, nothing beats it
And then, then there are days like today
Although the support site for iCloud tells me clearly, that there are no reported problems with iCloud at this time - I cannot load for instance Mail, Contacts, Calendar, Notes - consistently over some hours - and yes, I have reported this to Apple - consistently - over the last few hours.
One asks oneself how long the site takes to register problems.
Additionally accessing Apple support sites (including this one) has proved incredibly slow this evening - as if the problem were a more general one ( ? )
The most frustrating aspect of iCloud downtime for me is, that when I make changes in "Contacts" and sometimes in "Calendar" on my computer - they are sometimes not saved when iCloud is down.
It is a pattern I have noticed repeatedly over the last year.
Can anyone suggest ways to ensure this does not happen - there being no "save" function in "Contacts" or in "Calendar"
(would this not perhaps be a useful addition ? - particularly at the times that the iCloud is down)
Thank you
Znon
OSX 10.8.3, Mac Book Pro 13" late 2012, Safari 6.0.3Welcome to the Apple Community.
First check that all your settings are correct, that reminders syncing (calendars on a computer) is checked on all devices (system preferences > iCloud on a mac and settings > iCloud on a iPhone, iPad or iPod).
Make sure the reminders you are adding are added to your 'iCloud' account and not an 'On My Mac', 'On My Phone' or other non iCloud account (you can do this by checking in accounts on an iOS device by tapping the icon with three lines in the top left corner of the screen, or the right side panel by clicking on the small triangle to the right of the word 'Reminders' in iCal on a computer), non iCloud reminders will not sync.
If you are sure that everything is set up correctly and your reminders are in the iCloud group, you might try unchecking reminders syncing (calendars syncing on a computer) in the iCloud settings, restarting your device and then re-enabling notes syncing.
Maybe you are looking for
-
Is there a way of improving print clarity in iOS7 on my iPad & iPhone?
Since I 'upgraded' both my IPad mini & my IPhone 4S to the new operating system I've been both pleased and disappointed. Most displeasure is with the loss of the sharp black-on-white clarity that defined iCal in iOS6. The new half tone grey may work
-
Unlocking the iPhone 4S - Please, a REAL answer from someone official?
I've searched everywhere for this; I've read the other posts with the link to the "unlock confirmation" that's really from the "Droid" page; I've contacted customer service three times . . . each time as I was about to pull the trigger on purchasing
-
I am having a problem with email. I can receive and send, but when I delete, the deleted messages return into either Trash or Bin or both whether or not I have deleted them from my PC. The only way I can get rid of them permanently, is to go into my
-
Message stating my POP server has rejected my password
Of late - something like the last three weeks - I have been getting a Mail error intermittently. There is no pattern that I can establish. The error occurs when Mail attempts to check for new emails. I keep two accounts, and the error does not necess
-
How do I increase the size of fonts in Yosemite?
Hey all, recently I've been struggling to read the system fonts on Yosemite. I need to squint in order to see texts. For example, the font at the top left of the screen where the 'Apple logo' is it's hard for me to read the text. I've got a 21.5inch