Help: How to include logic in multiple CASE statements.
Hello Folks,
I have this Query where am converting from Access to Oracle. Am little confused on how to write multiple CASE statements.Apprecitae your help.
round(Sum(IIf(recovery_flg = 'NONCASH FEE RECEIVED',
IIf(feepaid < FEE, FEE - FEEPAID, FEE),
0)),
2)
*(1) you can nest CASE* - CASE in a CASE
CASE WHEN ecovery_flg = 'NONCASH FEE RECEIVED' THEN
CASE WHEN feepaid < FEE THEN ....
END
ENDor
*(2) you can try to rewrite it as one CASE*
CASE WHEN ecovery_flg = 'NONCASH FEE RECEIVED' AND feepaid < FEE THEN...
WHEN ecovery_flg = 'NONCASH FEE RECEIVED' AND feepaid >= FEE THEN ...
END
Similar Messages
-
How to optimized Multiple CASE statement
Hi..
Somebody please help me out to use most optimized Multiple CASE statement in below example..
Select
CAST(COUNT(DISTINCT(CASE WHEN period_id <350 THEN period_id END)) AS DECIMAL(30,0)) AS Column1, CAST(COUNT(DISTINCT(CASE WHEN period_id >=351 AND period_id<=375 THEN period_id END))
AS DECIMAL(30,0)) AS Column2,
CAST(COUNT(DISTINCT(CASE WHEN period_id >=376 AND period_id<=400 THEN period_id END)) AS DECIMAL(30,0)) AS Column3,
CAST(COUNT(DISTINCT(CASE WHEN period_id >=401 AND period_id<=450 THEN period_id END)) AS DECIMAL(30,0)) AS Column4,
CAST(COUNT(DISTINCT(CASE WHEN period_id >=451 AND period_id<=575 THEN period_id END)) AS DECIMAL(30,0)) AS Column5,
CAST(COUNT(DISTINCT(CASE WHEN pmc ='UVS' THEN pmc END)) AS DECIMAL(30,0)) AS Column6,
CAST(COUNT(DISTINCT(CASE WHEN pmc ='VAL' THEN pmc END)) AS DECIMAL(30,0)) AS Column7
FROM [Table1]
Thanks in Advance,
Deepak GoyalHow is an index going to help in a query with no where clause or join?
Rhetorical question but it brings to light the problem. This query is going to produce a table/index scan precisely because there's no where clause.
You need to change the way you are thinking about the problem. The problem isn't that you need a better performing case statement, the problem is that you need to minimize the number of records you ask SQL Server to read from disk. You do that
by using a where clause or by joining to a smaller table.
Here's one option which should give you the desired results while performing much better:
create index idx_period_id on Table1 (period_id)
create index idx_pmc on Table1 (pmc) include (period_id)
select (select count(distinct period_id) from Table1 where period_id < 350) as Column1,
(select count(distinct period_id) from Table1 where period_id between 351 and 375) as Column2,
(select count(distinct period_id) from Table1 where period_id between 376 and 400) as Column3,
(select count(distinct period_id) from Table1 where period_id between 401 and 450) as Column4,
(select count(distinct period_id) from Table1 where period_id between 451 and 575) as Column5,
(select count(distinct period_id) from Table1 where pmc = 'UVS') as Column6,
(select count(distinct period_id) from Table1 where pmc = 'VAL') as Column7 -
Help with multiple case statements
Hello,
I am new to BO. I am on XI 3.0. SQL 2005. In Designer, I am trying to create a measure in a financial universe that would end up being multiple case statements within one select. This is what I tried to do, but it doesn't work with the two case statements. Can I use an ELSE leading into the second CASE WHEN somehow? How can I accomplish this? Sorry for my ignorance!
CASE WHEN dbo.ClientBudgetYear.DateStage1Approved > 01/01/1900 AND dbo.ClientBudgetMonth.Month = 12 THEN dbo.ClientBudgetMonth.Stage1Sales END
CASE WHEN dbo.ClientBudgetYear.DateStage1Approved > 01/01/1900 AND dbo.ClientBudgetMonth.Month = 11 THEN dbo.ClientBudgetMonth.Stage1Sales END
Any Suggestions?
Thanks,
HollyHolly,
I don't know enough about your data or requirement to provide a solution, however, the construct that you post will not work because it causes you to build an object with multiple case statements when only one case statement per object is permitted. From what I see in your code I would be inclined to combine the two statements into one as such:
CASE WHEN dbo.ClientBudgetYear.DateStage1Approved > 01/01/1900 AND dbo.ClientBudgetMonth.Month in (11,12) THEN dbo.ClientBudgetMonth.Stage1Sales else null END
Thanks,
John -
Need help in this sql query to use Case Statement
hi All,
I have the below query -
SELECT DISTINCT OFFC.PROV_ID
,OFFC.WK_DAY
,CASE
WHEN OFFC.WK_DAY ='MONDAY' THEN 1
WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
END AS DOW
,OFFC.OFFC_OPENG_TIME
,OFFC.OFFC_CLSNG_TIME
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID='0000600'
WITH UR;
this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
can somebody help me in achieving that.
thanks,
iamhereHi,
Welcome to the forum!
That's called a Pivot .
Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
SELECT OFFC.PROV_ID
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_OPENG_TIME END) AS mon_opn
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS mon_cls
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_OPENG_TIME END) AS tue_opn
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS tue_cls
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID = '0000600'
GROUP BY offc.prov_id
;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
Edited by: Frank Kulash on Jan 6, 2011 8:22 PM -
New Logical Column w/Case Statement
OBIEE 11g
I have a created a logical column in the BMM that I would like to display a certain output if certain criteria are met. I have a case statement like the following:
CASE WHEN COLUMN1 = 'Honda'
AND COLUMN2 = 'Accord'
THEN 'Sedan' ELSE NULL END
However when I run a report in Answers with just the new logical column created it is not showing any values. I have validated that in the dimension table there are rows that meet the above criteria.I dont see anything wrong in the condition, I've tried with similar case for both based on logical columns and physical columns.
Can you check the physical query for the same to see how its executing?
Between: I think you can go with COLUMN2 to define the type of vehicle is? values you might have used for example, but the more specific column is enough to define the type. -
How to use Substring function with Case statement.
Hello Everyone,
I have one requirement where I have to use substring function on the field for report criteria.
E.G.
I have Branch Name Field where I have all branch names information, Now some of the branch names are too big with some extension after the name .
now i want to substing it but the character length varies for each branch.
so is there any way where we can use case statement where we can define that if branch name character are exceeding some value then substing it with this length.Try something like this:
CASE WHEN LENGTH(tablename.Branch_Name) > n THEN SUBSTRING(...) ELSE tablename.Branch_Name END
where n is the number of characters you want to start the break. -
How to include a table multiple times in InfoSet Query
Hi,
Is it possible to include a table more than once in an InfoSet Query, I created an InfoSet Query and Include Table A, then included Table B now i want to join Column 1 and 3 of Table A to be join with column1 of Table B, in other words, Table B is a Master data table, and Table A is a transaction data table, how this can be acheived.
Thanks
Akila. RYou cannot achieve this.
Instead, compound the column 1 with column 3 info objects and create join with Table B.
This will result in same intended functionality. -
if @CustNo = '0142' begin insert #custnos (CustNo, ClientNo) values ('0142', '1100') ,('0142', '1200') ,('0142', '1201') ,('0142', '1700') ,('0142', '1602') ,('0142', '1202') ,('0142', '1603') ,('0142', '2002') endstore procUSE ODSSupport
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
if exists (select * from dbo.sysobjects where id = object_id(N'dbo.pr_Load_PASOArgusClaims_Work') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
drop procedure dbo.pr_Load_PASOArgusClaims_Work
IF OBJECT_ID ('dbo.pr_Load_PASOArgusClaims_Work') IS NOT NULL
PRINT '<<< FAILED DROPPING PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
ELSE
PRINT '<<< DROP PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
END
GO
CREATE PROC dbo.pr_Load_PASOArgusClaims_Work
@BatchNo varchar(7) = null,
@CustNo char(4) = null,
@NewBatchNo varchar(7) = null
AS
/* Object dbo.pr_Load_PASOArgusClaims_Work 2006234 */
-- SSR# : 2242
-- Date : 12/23/2005
-- Author : Roxy Newbill
-- Description : Add new PASO BCAT 1602
-- SSR# 1932 - 2/22/2006 SEN - Add logic to include only ArgusCustNo - 0142
-- and change PharmacyClaim.ProcessDate to DateWritten
-- SSR# : 2419
-- Date : 08/22/2006
-- Author : Betty Doran
-- Description : PASO reports project
-- Correct mapping of Dispense fee amt from 'AmtProfFee' to 'DispenseFee' -
-- Mapping changed by Argus - did not inform PHP. Used in calcs for mClaimTotAmtCharge and
-- mClaimAmtAllowed fields.
-- SSR# : 2496
-- Date : 06/27/2007
-- Author : Roxy Newbil
-- Description : PASO Reporting Project
-- Add data load for new columns: Prescription No, Drug Name, NDC
-- SSR# : PEBB PROJECT
-- Date : 10/13/2009
-- Author : Tj Meyer
-- Description : Add BCAT 1201 for new PEBB business--
-- SSR# : 132707
-- Date : 12/17/2009
-- Author : Terry Phillips
-- Description : PASO Reporting Project
-- Fix data length issues for Argus_SubGroupId,Argus_PlanCode,vchParticipantId,
-- vchProviderId
-- SSR# : 3253
-- Date : 03/28/2011
-- Author : Susan Naanes
-- Description : PrescriptionNo increased in size from 7 to 12 characters
-- SSR# : SPOCK project
-- Date : 08/09/2012
-- Author : Raymond Beckett
-- Description : Modifed to bring in RxKey from PharmacyClaim instead of using identity value for iRecId
-- Also, modified to load any new batches since last batch loaded into PASOArgusClaims
-- if @BatchNo not supplied
-- Various 'fixes'
-- - removed grouping from initial query due to unique grouping caused by BatchNo, ClaimNumber, ClaimType
-- SSR# : TFS 5264 - Premera Remediation -(3997)
-- Date : 12/21/2012
-- Author : Satish Pandey
-- Description : Add BCATs 1202 and 1603 to the Where clause selecting pharmclm.ArgusClientNo as BCAT
-- SSR# : TFS 10286
-- Date : 1/15/2014
-- Author : Raymond Beckett
-- Description : Add HRI Customer Number and BCAT's. Also add Customer Number and alternate batchno to parameters
-- Only use '@NewBatchNo' if adding data from missed custno and the batchno already exists in PASOArgusClaims
-- ITSM Ticket : 1800925
-- Date : 4/15/2014
-- Author : Roxy Newbill
-- Description : Silverton Hospital had new BCAT (2002) with start of 2014 business. This was never accomodated for
-- Adding this BCAT in so that we can start capturing these claims (Note, special insert being done to capture
-- all BCAT 2002 claims prior to this fix.)
-- ITSM Ticket : TFS 14587 -Intel BCAT Remediation
-- Date : 08/14/2014
-- Author : Andrew Omofonma
-- Description : Added BCAT's (1604,& 2103) for Intel
SET NOCOUNT ON
DECLARE @iCount int
create table #tmpArgusWork (
iRecId int,
BatchNo varchar (7) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
BatchDateTime datetime NULL ,
BatchStatus varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
ReadyDateTime datetime NULL ,
Argus_GroupId varchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
Argus_SubGroupId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
Argus_ClassId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
Argus_PlanCode varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
Argus_BusinessCategory varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
FacetsClaimSubType varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PASOClaimType varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
vchClaimNumber varchar (14) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
dtPaidDate datetime NULL ,
dtProcessDate datetime NULL ,
dtServiceDate datetime NULL ,
vchParticipantId varchar (14) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
vchProviderId varchar (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
vchProviderName varchar (55) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
mClaimTotAmtCharge money NULL ,
mClaimAmtDiscount money NULL ,
mClaimAmtAllowed money NULL ,
mClaimAmtDenied money NULL ,
mClaimAmtDeduct money NULL ,
mClaimAmtCoinsurance money NULL ,
mClaimAmtCopay money NULL ,
mClaimAmtPaid money NULL ,
PASO_GroupId varchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PASO_SubGroupId varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PASO_ClassID varchar (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PASO_PlanCode varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
PASO_BusinessCategory varchar (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
RecordStatus varchar (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
ErrorDesc varchar (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PrescriptionNo char(12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
DrugName varchar(30)COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
NDC char(11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
create table #batches (
BatchNo char(7) not null
primary key (BatchNo))
create table #custnos (
CustNo char(4),
ClientNo char(5), -- bcats associated with the customer
primary key (CustNo, ClientNo)
DECLARE
@len_Argus_SubGroupId smallint,
@len_Argus_PlanCode smallint,
@len_vchParticipantId smallint,
@len_vchProviderId smallint
--Get field lengths for the following fields
SELECT @len_Argus_SubGroupId = 4, --datalength([@tmpArgusWork].[Argus_SubGroupId]),
@len_Argus_PlanCode = 8, --datalength(@tmpArgusWork.Argus_PlanCode),
@len_vchParticipantId = 14, --datalength(@tmpArgusWork.vchParticipantId),
@len_vchProviderId = 12 --datalength(@tmpArgusWork.vchProviderId)
declare @maxbatch char(7)
IF @BatchNo IS NULL
begin
-- assume normal run. Add ClientNo's and custno's to tables
insert #custnos (CustNo, ClientNo)
values ('0142', '1100')
,('0142', '1200')
,('0142', '1201')
,('0142', '1700')
,('0142', '1602')
,('0142', '1202')
,('0142', '1603')
,('0142', '2002')
,('0142', '1604')
,('0142', '2103')
,('0669', '*')
-- get batches loaded since last batch loaded into PASOArgusClaims
SELECT @maxbatch=Max(BatchNo)
FROM ODSSupport.dbo.PASOArgusClaims
declare @dt datetime
declare @ds datetime
select @dt = MIN(DateTimeStamp)
from ODS.dbo.PharmacyClaim_Common
where BatchNo <= @maxbatch
and DateTimeStamp > DATEADD(dd,-16,getdate())
insert #batches (BatchNo)
select distinct BatchNo
from ODS.dbo.PharmacyClaim_Common pcc
inner join #custnos ct
on ct.CustNo = pcc.ArgusCustNo
and (
ct.ClientNo = '*'
or
ct.ClientNo = pcc.ArgusClientNo
where DateTimeStamp > @dt
; -- batch may have had a claim altered since last load, drop any batches already loaded into PASOArgusClaims
with pba as (
select distinct BatchNo
from ODSSupport.dbo.PASOArgusClaims
delete ba
from #batches ba
inner join pba
on pba.BatchNo = ba.BatchNo
end
else if @NewBatchNo is not null and @CustNo is not null
begin
--make sure we haven't already done this batch number/customer combination
set @maxbatch = @NewBatchNo
SELECT @iCount=count(*)
FROM PASOArgusClaims
WHERE BatchNo=@maxbatch
and Argus_BusinessCategory = @CustNo
IF @iCount > 0
begin
PRINT 'Msg: Batch ' + @maxbatch + ' already exists for CustNo ' + @CustNo + '.'
end
else
begin
if @CustNo = '0142'
begin
insert #custnos (CustNo, ClientNo)
values ('0142', '1100')
,('0142', '1200')
,('0142', '1201')
,('0142', '1700')
,('0142', '1602')
,('0142', '1202')
,('0142', '1603')
,('0142', '2002')
,('0142', '1604')
,('0142', '2103')
end
if @CustNo = '0669'
begin
insert #custnos (CustNo, ClientNo)
values ('0669', '*')
end
insert #batches (BatchNo)
values (@BatchNo)
end
end
else
begin
--make sure we haven't already done this batch number
set @maxbatch = @BatchNo
SELECT @iCount=count(*)
FROM PASOArgusClaims
WHERE BatchNo=@maxbatch
IF @iCount > 0
begin
PRINT 'Msg: Batch ' + @maxbatch + ' already loaded.'
end
else
begin
insert #batches (BatchNo)
values (@maxbatch)
end
end
** Insert Pharmacy Claims to temporary table
INSERT INTO #tmpArgusWork
SELECT
pharmClm.RxKey,
isnull(@NewBatchNo, pharmClm.BatchNo),
pharmclm.OrigDateTimeStamp as BatchDateTime,
'PENDING' as BatchStatus,
NULL as ReadyDateTime,
substring(pharmClm.GrpNumber,1,8)as Argus_GroupID,
left(pharmClm.ArgusSubgroup1,@len_Argus_SubGroupId) as Argus_SubgroupID,
substring(pharmClm.GrpNumber,9,4) as Argus_ClassId,
substring(pharmClm.GrpNumber,13,@len_Argus_PlanCode) as Argus_PlanCode,
pharmClm.ArgusClientNo as Argus_BusinessCategory,
'' as vchFacetsClaimSubtype,
PASOClaimType = CASE WHEN pharmClm.ClaimType='A'
THEN 'PHARMACY-ADJUST'
ELSE 'PHARMACY'
END,
pharmClm.ClaimNo,
pharmClm.DateCutoff as dtPaidDate,
pharmClm.DateWritten as dtProcessDate,
NULL as dtServiceDate,
left(pharmClm.MemberId,@len_vchParticipantId) as vchParticipantId,
left(pharmClm.PharmacyNo,@len_vchProviderId) as vchProviderId,
vchProviderName = CASE WHEN pharmclm.PayMemberInd = 'Y'
THEN 'Member Reimbursement'
ELSE pharm.PharmName
END,
mClaimTotAmtCharge = CASE WHEN pharmclm.PayMemberInd = 'Y' -- When this is a member reimbursement use the amt paid
THEN isnull(pharmClm.IngredientCostPaid,0) + isnull(pharmClm.DispenseFee,0) + isnull(APSFee,0) -- as amt charged.
ELSE isnull(pharmClm.AmtBilled,0)
END,
case when pharmclm.PayMemberInd = 'Y'
then isnull(pharmClm.AmtRejected,0) * -1
else isnull(pharmClm.AmtBilled,0) - isnull(pharmClm.IngredientCostPaid,0) - isnull(pharmClm.DispenseFee,0) - isnull(APSFee,0) -isnull(pharmClm.AmtRejected,0)
end as mClaimAmtDiscount,
isnull(pharmClm.IngredientCostPaid,0) + isnull(pharmClm.DispenseFee,0) + isnull(APSFee,0) as mClaimAmtAllowed,
isnull(pharmClm.AmtRejected,0) as mClaimAmtDenied,
isnull(pharmClm.MemberPaidAmt,0) - isnull(pharmClm.MemberCopayAmt,0) as mClaimAmtDeduct,
0 as mClaimAmtCoinsurance,
isnull(pharmClm.MemberCopayAmt,0) as mClaimAmtCopay,
isnull(pharmClm.AmtPaid,0) + isnull(APSFee,0) as mClaimAmtPaid,
NULL as PASO_GroupID,
NULL as PASO_SubgroupID,
NULL as PASO_ClassID,
NULL as PASO_PlanCode,
NULL as PASO_BusinessCategory,
'OK' as RecordStatus,
NULL as ErrorDesc,
PrescriptionNo = pharmClm.PrescriptionNo,
DrugName = pharmClm.DrugName,
NDC = pharmClm.NDC
FROM ODS..PharmacyClaim as pharmClm
LEFT JOIN ODS..pharmacy as pharm on
pharmClm.PharmacyNo = pharm.PharmacyNo
INNER join #batches ba
on ba.BatchNo = pharmClm.BatchNo
INNER join #custnos ct
on ct.CustNo = pharmClm.ArgusCustNo
and (
ct.ClientNo = '*'
or
ct.ClientNo = pharmClm.ArgusClientNo
WHERE pharmClm.ClaimType in ('P','A') -- Processed or Adjusted
--AND pharmClm.ProcessCode <> 'MC' --code doesn't exist
--GROUP BY
-- pharmClm.BatchNo,
-- substring(pharmClm.GrpNumber,1,8),
-- substring(pharmClm.GrpNumber,9,4) ,
-- substring(pharmClm.GrpNumber,13,@len_Argus_PlanCode),
-- pharmClm.ArgusSubgroup1,
-- pharmClm.ClaimNo,
-- pharmClm.ArgusClientNo,
-- pharmClm.DateCutoff,
-- pharmClm.DateWritten,
-- pharmClm.MemberId,
-- pharmClm.PayMemberInd,
-- pharmClm.PharmacyNo,
-- pharm.PharmName,
-- pharmClm.OrigDateTimeStamp,
-- pharmClm.ClaimType,
-- pharmClm.PrescriptionNo,
-- pharmClm.DrugName,
-- pharmClm.NDC
IF @@RowCount=0
BEGIN
PRINT 'Msg: No records found.'
RETURN
END
--Update the Discount column for these Pharmacy Claims
--UPDATE @tmpArgusWork
--SET mClaimAmtDiscount=mClaimTotAmtCharge-mClaimAmtAllowed-mClaimAmtDenied
** Get the lowest service Date for each claim and update temp table
UPDATE #tmpArgusWork
SET dtServiceDate = (SELECT min(pharmclm.DateSvc)
FROM ODS..pharmacyClaim AS pharmclm
WHERE pharmclm.ClaimNo = tcpr.vchClaimNumber
AND pharmclm.MemberID = tcpr.vchParticipantId)
FROM #tmpArgusWork as tcpr
** Copy over the eligibility fields that Argus provided
UPDATE #tmpArgusWork
SET PASO_GroupId = Argus_GroupID,
PASO_SubGroupId = Argus_SubGroupId,
PASO_ClassID=Argus_classid,
PASO_PlanCode=Argus_PlanCode,
PASO_BusinessCategory=Argus_BusinessCategory
FROM #tmpArgusWork pw
WHERE COALESCE(Argus_GroupID,'') <> ''
OR COALESCE(Argus_SubGroupId,'') <> ''
OR COALESCE(Argus_classid,'') <> ''
OR COALESCE(Argus_PlanCode,'') <> ''
OR COALESCE(Argus_BusinessCategory,'') <> ''
** If Argus did not provide all 5 eligibility fields, get them from faEnrollmentHistory
** based on the group, member, date of service
UPDATE #tmpArgusWork
SET PASO_GroupId = eh.GroupId,
PASO_SubGroupId = eh.SubGroupId,
PASO_ClassID=eh.Class,
PASO_PlanCode=eh.PlanCode,
PASO_BusinessCategory=eh.BusinessCategory
FROM #tmpArgusWork pw
INNER JOIN ODS..FAEnrollmentHistory eh
ON eh.MemberID =pw.vchParticipantID
AND eh.Groupid =pw.Argus_GroupID
AND eh.eligind='Y'
AND eh.ProcessCode<>'ID'
AND pw.dtServiceDate BETWEEN eh.EligEffDate AND eh.EligTermDate
WHERE COALESCE(Argus_GroupID,'') = ''
OR COALESCE(Argus_SubGroupId,'') = ''
OR COALESCE(Argus_classid,'') = ''
OR COALESCE(Argus_PlanCode,'') = ''
OR COALESCE(Argus_BusinessCategory,'') = ''
** If we have eligibility for all records, go ahead and set the ready date to today.
IF NOT EXISTS ( SELECT *
FROM #tmpArgusWork
WHERE COALESCE(PASO_GroupID,'') = ''
OR COALESCE(PASO_SubGroupID,'') = ''
OR COALESCE(PASO_ClassID,'') = ''
OR COALESCE(PASO_PlanCode,'') = ''
OR COALESCE(PASO_BusinessCategory,'') = '')
BEGIN
UPDATE #tmpArgusWork
SET ReadyDateTime=convert(varchar(10),GetDate(),101),
BatchStatus='READY'
END
ELSE
BEGIN
PRINT 'Msg: Exceptions found.'
UPDATE #tmpArgusWork
SET RecordStatus='ERR',
ErrorDesc='No valid Eligible span for this Member/Group/Subgroup at time of Service'
WHERE COALESCE(PASO_GroupID,'') = ''
OR COALESCE(PASO_SubGroupId,'') = ''
OR COALESCE(PASO_ClassID,'') = ''
OR COALESCE(PASO_PlanCode,'') = ''
OR COALESCE(PASO_BusinessCategory,'') = ''
END
** Insert the records into the final table.
INSERT INTO PASOArgusClaims
SELECT * FROM #tmpArgusWork
SET NOCOUNT OFF
END
GO
-- Verify that the stored procedure was created successfully.
IF OBJECT_ID ('dbo.pr_Load_PASOArgusClaims_Work') IS NOT NULL
PRINT '<<< CREATED PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
ELSE
PRINT '<<< FAILED CREATING PROCEDURE dbo.pr_Load_PASOArgusClaims_Work >>>'
GO
GRANT EXECUTE ON dbo.pr_Load_PASOArgusClaims_Work to role_ODSLoad
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ONthis part of the code below
if@CustNo
= '0142'
begin
insert #custnos(CustNo,
ClientNo)
values ('0142',
'1100')
,('0142',
'1200')
,('0142',
'1201')
,('0142',
'1700')
,('0142',
'1602')
,('0142',
'1202')
,('0142',
'1603')
,('0142',
'2002')
end
store proc
How do I covert it to a common table where the values can be selected from when needed. -
How to eliminate NULL values from case statement?
I have the following query where I am trying to eliminate the NULL record. How can I do this? My query:
select
AttendedSchoolLast3Months = case
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'BC349A1E-65A1-4497-A38A-116C83B2028F' then 2 --No
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'A529C643-60A7-4D79-AC67-1A8F70791934' then 1 --Yes
end
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A'
And the result currently is:
AttendedSchoolLast3Months
1
NULL
When I ran this query:
select distinct --attendedschoollast3months
d.*
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
--join [education_level] e (nolock) on e.[EducationLevel] = udl1.[description]
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A'
I get this:
event_log_id people_id group_profile_id actual_date test_header_id test_setup_details_id test_domains_info_id question_caption question_code test_details_answers_id update_log_id test_details_id numeric_value scrnval_id picklist_value remarks narrative test_setup_details_answers_id is_checked date_value details_type_code test_setup_answers_caption test_setup_answers_order test_setup_answers_value output_code answers_category_id answers_category answers_category_code
24E8F88F-9648-4714-9394-D5A3F642C0F0 7A9ACEE4-ABD5-4905-A54E-659A81048A1A NULL 2013-09-26 17:00:00.000 24E8F88F-9648-4714-9394-D5A3F642C0F0 67CDCF44-6308-4E15-8543-3C85DE4C6D4D NULL Attended school in the last 3 months NULL 1BB75044-A65C-4464-ADB9-0CA991019907 7CDD1A4F-41F4-403C-A85E-7FF51B761FF0 3F04BBFF-8DE9-4283-842F-E53A536E3E46 NULL AA5639E4-E60C-473F-9B72-354472C11F5B A529C643-60A7-4D79-AC67-1A8F70791934 NULL NULL 5979600C-B4E6-42DF-BF45-8AFF15ACDD7D 0 NULL PICKLIST Click here for list 1 NULL NULL NULL NULL NULL
24E8F88F-9648-4714-9394-D5A3F642C0F0 7A9ACEE4-ABD5-4905-A54E-659A81048A1A NULL 2013-09-26 17:00:00.000 24E8F88F-9648-4714-9394-D5A3F642C0F0 EBDFBCA5-6E57-4907-9DEF-A1E118F3AB2D NULL Highest grade completed NULL 8F7F4644-4E67-4821-B0FC-A192389F994D 7CDD1A4F-41F4-403C-A85E-7FF51B761FF0 F6C59E67-EC74-4F0C-8EE8-AB372F22255D NULL 4536DD06-871D-4FA7-BA8A-552DB2CA59BC D77F0CAB-505E-4838-AECE-01BAAE8B8EB2 NULL NULL E7C9ECB7-7B40-4115-A6DB-BC752116D68D 0 NULL PICKLIST Click here for list 1 NULL NULL NULL NULL NULL
Ryan DHi,
what I understood from above is that u want to filter NULL records and want to display only not null records. Try below query.
SELECT * FROM(select
AttendedSchoolLast3Months = case
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'BC349A1E-65A1-4497-A38A-116C83B2028F' then 2 --No
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'A529C643-60A7-4D79-AC67-1A8F70791934' then 1 --Yes
end
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A' ) AWHERE AttendedSchoolLast3Months IS NOT NULLTry this query.
Thanks Shiven:) If Answer is Helpful, Please Vote -
Multiple case statements with aggregates- SQL
Hi guys
Here is my ddl
create table TestTable
Bill_date DATE,
Phone_no NUMBER(10),
Planlvl1 VARCHAR2(20),
Planlvl2 VARCHAR2(20)
Revenue NUMBER
INSERT INTO TestTable
Values
('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014'' , 64221, 'Bundle', 'PlanA', '$32'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
Expected Outcome:
Bill_date PlanLvl2 PhonenoCount
'01/01/2014' 'SpecialPack1' 1
'01/01/2014' 'SpecialPack2' 3
'01/01/2014' 'Casual1' 1
'01/01/2014' 'Casual2' 1
'01/01/2014' 'PlanA' 1
'01/01/2014' 'PlanB' 1
Basically I have to count all the phone nos grouped by plans in a certain way:
If PlanLvl1 = Bundle, then I have to look at planLvl2 and see if that phone no has ' SpecialPack%' ,and also another plan,them 'Special pack' gets the priority and the phone no gets counted in the special pack.
In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue.
In case where PalnLvl is 'Bundle' and a phone no has multiple 'Special Packs' and a non special, that ph no will only be counted once under 'Special Pack; of higher rev as compared to the special pack of lower rev.
Now there are also PlanLvl1 which are 'Non_Bundles' which means they do not have any 'SpecialPacks' but if a ph no with 'NonBundle' plan has 2 different plans under planLvl2, we need to count that ph no for eack planLvl2..
Then there is a scenario where a ph no can have bundles as well as non bundles and in that case we just have to count that ph no in bundles and not in non-bundles.
As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these
Hope this helpsI;m not sure exactly what your rules are since you specify both "In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue" and "As I mentioned ,
'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these". I went with the rule "As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these" since that seemed to match
the result you say you want. I also changed the datatypes to valid SQL Server datatypes.
create table TestTable
Bill_date DATE,
Phone_no Decimal(10,0),
Planlvl1 VARCHAR(20),
Planlvl2 VARCHAR(20),
Revenue money
INSERT INTO TestTable
Values
('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 64221, 'Bundle', 'PlanA', '$32'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
;With cte As
(Select Bill_date, Phone_no, Planlvl1, Planlvl2, Revenue,
Row_Number() Over (Partition By Bill_Date, Phone_no Order By
Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack2' Then 0 Else 1 End,
Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack1' Then 0 Else 1 End,
Case When Planlvl1 = 'Bundle' Then Revenue Else -1 End Desc) As rn,
Min(Case When Planlvl1 = 'Bundle' Then 0 Else 1 End) Over(Partition By Bill_Date, Phone_no) As NumberHasOnlyNonBundle
From TestTable)
Select Bill_date, Planlvl2, COUNT(*) As PhoneNoCount
From cte
Where rn = 1 Or NumberHasOnlyNonBundle = 1
Group By Bill_date, Planlvl2;
Tom -
How do I use switch and case statements to fill more than one other field?
Hi all,
I'm new to the community.
I'm trying to make an existing form more user friendly for my coworkers. I want to use a switch and case approach in a drop-down list field so that the selection fills two seperate other fields with different info related to the selection.
I can already do this with one field, but if I add a second target field under an existing case the text doesn't appear there when I make the selection from the dropdown.
Basically, I'm asking if I can do this:
switch
(sNewSel){
case "1": // Selection 1 Row2.Field1
= "text for field 1";
Row1.Field2 = "text for field 2";
break;
etc.
It works if the "row1.field2" option isn't there, but not when it is present.
Any takers?I'm not sure if I will be able to send you the form. There may be too much to redact.
Would this last bit of code in the cell affect anything?
if
(bEnableTextField)
{Row2.Field1.access
= "open"; // enable field
Row2.Field1.caption.font.fill.color.value= "0,0,0"; // set caption to black
That is, do I also need to repeat the same thing for the second target cell (Row1.Field2)?
What would be possible hang ups that would prevent it from working correctly?
Dave
By the way, I'm not sure if my other attachment posted. I am trying again. -
How to include the insert picture option in the PDF form?
Hi, Can some one please help How to include the insert picture option in the PDF form? I am using acrobat XI pro and trying to use an evaluation form which requires to insert product pictures.
Here's a link to a previous topic where this was discussed: http://forums.adobe.com/message/6050458
-
Q: how to include a page in a region
Hi all,
i need some help
how to include the URL of a page in a region, my requirement is that i have some links in the page and i need when i press a link a region under it will be rendered below it not in another page
the links is ready and the pages is ready
just i want a the region to contain a url based on the selected link.
i know how to make a region rendered or not.
and i have tried to use URiInclude but i couldn't figure out exactly how to do it
i have also searched the forum and i couldn't find something about it.
so please if any one knows the solution or can provide me with a link, i will be very thankful
thanksuser604057,
Technically you can't add a page to another page. A page can have only one pagelayout region. So you will have to make a copy of those pages as regions without a pagelayout region and use.
--Shiv -
How to include the Age and Age operator in Dashboard prompts
I wouild like to create two new dashboard prompts 'Age' and 'Age Operator' both as drop downs.
The 'Age' prompt should have the values from 1-100 as dropdown for the users to select from.
The 'Age Operator' should have the values <, <=, >, >=, = as dropdown for the users to select.
I have PERS_DOB column in Person table. I do not have any operator values stored in any tables.
How can I create these two dashboard prompts so that the user can select the values from the
dropdown list and filter the results against.
For example:
User select Age 20 from Age dropdown prompt and '<' from the Age operator prompt the results
should filter based on the above and should get us the records for the people whose
Age is less than 20.
I appreciate any help on this.
Thanks.You could try this:
1) For the "age operator" prompt, use words to describe the operators (e.g., "less than" rather than the symbol <=, etc.). (I'll assume you know how to build the prompt using CASE statements and UNION. It's pretty straightforward.)
2) Build 5 small reports, one for each operator, that only returns a row when the particular operator is selected in the prompt. Each of these reports will be in the guided navigation of a separate section.
3) Now, build 5 versions of your report with a filter on the "Age" prompt, one report that calculates the 5 different permutations of the age chosen (i.e., less than prompt, less than or equal to prompt, etc.) and put each report in the guided navigation section that corresponds to the applicable small report you built in step 2. So, for example, for the section that returns a row when "less than" is chosen, put the report that filters for "age less than 'age prompt'."
So here is how it works: When the user selects an age and operator, only the section that corresponds to the operator selected will display because of the guided navigation. The other 4 sections will not show, because the small report in the guided navigation part of the section will return no rows. -
Need help to write case statement
Hi Guys,
I have dashboard in which its has pprompt called PROPMT1 in that prompt it has three values A,B,C
but iwant the full abbreviation of those values like A=APPLE B=BOY and C=Cindy
and also in the report i have the coloumn is prompted by PROMPT1 which has again A,B,C values that need to be modified as A=APPLE B=BOY and C=Cindy
how can i do it with case statement.For the prompt, write this in the Show window>SQL Results:
1) CASE WHEN 1=0 THEN char_columnname ELSE 'A = APPLE' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'B = BOY' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'C = Cindy' END FROM "your subject area"
2) Save the prompt to a presentation variable, pv_choice
This will give you your three values. Make sure you use a CHAR column, doesnt matter what column, though.
For the report,
1) Create a BINS column on the column that contains the A, B, C values and make the BINS A = APPLE, B = BOY, C = Cindy just like the prompt values.
2) Now put a filter on this BINS column and set it equal to your pv_choice presentation variable.
That's it.
NOTE: Obviously, if you want the prompt values to just say "APPLE," "BOY," and "Cindy," then take off the 'A = ', 'B = ' and 'C = ' appropriately. Same for the BINS in your report.
Edited by: David_T on Jun 8, 2011 10:57 AM
Maybe you are looking for
-
RFC Client Interface upgrade from 4.6c to ECC 6.0
We're currently using BODI v.6.1, and have an existing Client Interface using SAP 4.6c. They now updgraded their system to ECC 6.0, and we're now having problem in connecting to that R/3 system, wherein the password logon being locked everytime we co
-
Previously, using firefox 3.6.1, when I opened a secure or encrypted page, the lock icon appeared on that page. When I upgraded to firefox 4.0, the lock icon is no longer appearing when I open a secure page. Please confirm whether this has been remov
-
How prevent JTable row selection?
there are three selection mode for JTable, MultiIntervalSelection, SingleIntervalSelection and SingleSelection. Is there a no selection mode?
-
Is it possible to define a form (subprocedure) inside a user exit? When I try it complains that I'm trying to define a form inside of a function. Of course I have no choice because the whole user exit is a function. What's the best way to work aro
-
Can't render H264 from Render Cue!!!!!
I've got a 1920 x 1080 24fps comp and I'm trying to render it with the render cue as a H.264 1920 X 1080 24fps file and I get this every time: After Effects: AEGP Plugin Media IO Plugin There is a mismatch between Output Module settings and Transcode