How do i convert the following case statement to a table and still implement it in the store procedure.

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 ON

this 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.

Similar Messages

  • When opening Bridge (CS6) I get the following message: "Bridge encountered a problem and is unable to read the cache. Please try purging the central cache in Cache Preferences to correct the situation" I tried and after selecting purge cache it does not a

    When opening Bridge (CS6) I get the following message: "Bridge encountered a problem and is unable to read the cache. Please try purging the central cache in Cache Preferences to correct the situation" I tried and after selecting purge cache it does not allow me to select OK. Also Bridge keeps saying "Building Criteria" with the spinning wheel and nothing happens. I tried uninstalling and reinstalling to no avail. Please help:)

    Maybe a Preferences reset can help:
    Numerous program settings are stored in the Adobe Bridge preferences file, including display, Adobe Photo Downloader, performance, and file-handling options.
    Restoring preferences returns settings to their defaults and can often correct unusual application behavior.
    Press and hold the Ctrl key (Windows) or the Option key (Mac OS) while starting Adobe Bridge.  
    In the Reset Settings dialog box, select one or more of the following options:  
      Reset Preferences 
    Returns preferences to their factory defaults. Some labels and ratings may be lost. Adobe Bridge creates a new preferences file when it starts.
    Purge Entire Thumbnail Cache
    Purging the thumbnail cache can help if Adobe Bridge is not displaying thumbnails properly. Adobe Bridge re-creates the thumbnail cache when it starts.
    Reset Standard Workspaces
    Returns Adobe predefined workspaces to their factory default configurations.
    Click OK, or click Cancel to open Adobe Bridge without resetting preferences.   

  • How to write the following CASE statement

    I need to calculate Retainer amount. The derivation of it is as follows:
    "A fixed value of 10000 per month for employees who have served for less than 2 years and 15000 for more than 2 years. This increment will be affected in two cycles a year, in the January or July."
    The years of service can be calculated using date_of_joining.

    Use this logic
    SELECT DECODE(SIGN(SYSDATE - ADD_MONTHS(HIREDATE,24)),-1,10000,1,15000) from <table_name>Is this you need
    In every Jan/July month employee get a Sal+Fixed allownce (10000 if less than 2 years in company/15000 if more than 2 years). In other month they get just the salary
    SELECT CASE WHEN TO_CHAR(SYSDATE,'MM') IN ('01','07') THEN
                   CASE WHEN SYSDATE- ADD_MONTHS(HIREDATE,24)> 0 THEN
                        SAL+15000
                    ELSE
                        SAL+10000
                    END
            ELSE
              SAL
            END  SAL
    FROM EMP
    /Edited by: Lokanath Giri on १७ सितंबर, २०१० ४:५६ अपराह्न

  • TS2771 I Cannot Turn On My Ipod Touch 5G AT ALL, I Tries holding the 2 buttons, i did DFU Mode, i tried with 5 different chargers, ad the 5 chargers was all brand new, and still when i connect the brand new chargers, it wont, and it is OUT out of battery.

    I Explained It Up there^ i cannot turn on no matter, what and today is the 7th Of January, and my hardware warranty from apple ends tomorrow, and i am out of country, and will be coming back on 14th, and i am in Poland, there is no Apple stores at all, i checked, even if there is, it would be 4 hours or more away from the city where i am, and idk what to do, i read a bunch of stuff, i tried everything, and my ipod is clean, no scratches, no cracks, beautiful, and is shiny, and ha sbeen protected since last year, and no damage, and it has never been dropped, what do i do?

    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable
    - Try on another computer                            
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar                                     

  • How to tune the following sql statements which has two unions in oracle 10g

    It takes a long time to run the following sql statement in 10g. Each select brings back about 4 million rows and there will be about 12 million rows. When I run each select statements seprately in sqlplus I can see the data immedaitely but when I run it as whole with two unions in the select it just takes very very long time? I want to know how to make this run faster? Can we add hints? or is it because of any table space? Any help is appreciated.
    select
    D.EMPLID
    ,D.COMPANY
    ,'CY'
    ,D.CALENDAR_YEAR
    ,D.QTRCD
    ,D.ERNCD
    ,D.MONTHCD
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,D.GRS_YTD
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,D.HRS_YTD
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FY'
    ,(case when D.MONTHCD > '06' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD) + decode(sign(3-to_number(D.QTRCD)),1,2,-2),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FF'
    ,(case when D.MONTHCD > '09' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD)+decode(sign(4-to_number(D.QTRCD)),1,1,-3),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD)+decode(sign(10-to_number(D.MONTHCD)),1,3,-9),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    Edited by: user5846372 on Mar 11, 2009 8:55 AM

    Hi,
    What i observed is that your table name and where clause is same in all the thress SELECTs whereas columns having some manipulations that is not going to be unique. I guess you can easily replace UNION with UNION ALL.
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'Note: I am not aware of your data and business requirement. Please test the result before removing. It is just a suggetion
    Cheers,
    Avinash

  • Increase performance of the following SELECT statement.

    Hi All,
    I have the following select statement which I would want to fine tune.
      CHECK NOT LT_MARC IS INITIAL.
      SELECT RSNUM
             RSPOS
             RSART
             MATNR
             WERKS
             BDTER
             BDMNG FROM RESB
                          INTO TABLE GT_RESB 
                          FOR ALL ENTRIES IN LT_MARC
                          WHERE XLOEK EQ ' '
                          AND MATNR EQ LT_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND BDTER IN S_PERIOD.
    The following query is being run for a period of 1 year where the number of records returned will be approx 3 million. When the program is run in background the execution time is around 76 hours. When I run the same program dividing the selection period into smaller parts I am able to execute the same in about an hour.
    After a previous posting I had changed the select statement to
      CHECK NOT LT_MARC IS INITIAL.
      SELECT RSNUM
             RSPOS
             RSART
             MATNR
             WERKS
             BDTER
             BDMNG FROM RESB
                          APPENDING TABLE GT_RESB  PACKAGE SIZE LV_SIZE
                          FOR ALL ENTRIES IN LT_MARC
                          WHERE XLOEK EQ ' '
                          AND MATNR EQ LT_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND BDTER IN S_PERIOD.
      ENDSELECT.
    But the performance improvement is very negligible.
    Please suggest.
    Regards,
    Karthik

    Hi Karthik,
    <b>Do not use the appending statement</b>
    Also you said if you reduce period then you get it quickly.
    Why not try dividing your internal table LT_MARC into small internal tables having max 1000 entries.
    You can read from index 1 - 1000 for first table. Use that in the select query and append the results
    Then you can refresh that table and read table LT_MARC from 1001-2000 into the same table and then again execute the same query.
    I know this sounds strange but you can bargain for better performance by increasing data base hits in this case.
    Try this and let me know.
    Regards
    Nishant
    > I have the following select statement which I would
    > want to fine tune.
    >
    >   CHECK NOT LT_MARC IS INITIAL.
    > SELECT RSNUM
    >          RSPOS
    > RSART
    >          MATNR
    > WERKS
    >          BDTER
    > BDMNG FROM RESB
    >                       INTO TABLE GT_RESB 
    > FOR ALL ENTRIES IN LT_MARC
    >                       WHERE XLOEK EQ ' '
    > AND MATNR EQ LT_MARC-MATNR
    >                       AND WERKS EQ P_WERKS
    > AND BDTER IN S_PERIOD.
    >  
    > e following query is being run for a period of 1 year
    > where the number of records returned will be approx 3
    > million. When the program is run in background the
    > execution time is around 76 hours. When I run the
    > same program dividing the selection period into
    > smaller parts I am able to execute the same in about
    > an hour.
    >
    > After a previous posting I had changed the select
    > statement to
    >
    >   CHECK NOT LT_MARC IS INITIAL.
    > SELECT RSNUM
    >          RSPOS
    > RSART
    >          MATNR
    > WERKS
    >          BDTER
    > BDMNG FROM RESB
    > APPENDING TABLE GT_RESB
    >   PACKAGE SIZE LV_SIZE
    >                     FOR ALL ENTRIES IN LT_MARC
    >   WHERE XLOEK EQ ' '
    >                     AND MATNR EQ LT_MARC-MATNR
    >   AND WERKS EQ P_WERKS
    >                     AND BDTER IN S_PERIOD.
    > the performance improvement is very negligible.
    > Please suggest.
    >
    > Regards,
    > Karthik
    Hi Karthik,

  • Explain me the following replace statement

    Hi guys,
    Please explain me the following replace statement with an example :
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc WITH ''''''.
    Please explain me the purpose of the above statement by showing the input and output.
    Regards,
    Vishu.

    Hi Rob,
    It's working fine .Thank you.But I just want to know the purpose of it as the functionality in one of the programs I have seen is as below  :
    Requirement :
    Need to get all the material groups and description2 based on the material descriptions we enter in the selection-screen .
    The program is coded in such a way that all the single quotes are replaced with double quotes :
    The following 3 statements are written in the code  :
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc  WITH ''''''.
    REPLACE ALL OCCURRENCES OF '*'  IN materialgroup_desc WITH '%'.
    REPLACE ALL OCCURRENCES OF '''' IN materialgroup_desc  WITH ''''''.
    and finally the result string is concatenated between quotes again to query the data.
    For instance if we give MAT'ER*IAL as the input it is converted to 'MAT''''ER%IAL'
    and by querying with a select statement using
    materialgroup_desc LIKE 'MAT''''ER%IAL' we are getting the required data.
    Hope you understand mny question.Please explain me why we are replacing the single quotes with double quotes 2 times.Is it a way to skip the special characters.
    Regards,
    Vishu shetty.

  • HT201364 texmate and git 1.8.4.2 won't work on OS X Mavericks. I've downloaded them repeatedly and the following errors display "Textmate is damaged and can't be opened"  and Git states "can't be opened because it's from an unidentified developer". Please

    texmate and git 1.8.4.2 won't work on OS X Mavericks. I've downloaded them repeatedly and the following errors display "Textmate is damaged and can't be opened"  and Git states "can't be opened because it's from an unidentified developer". Please help!

    MedlockDustin,
    for TextMate, you’ll need to download TextMate 2.0 alpha, since earlier versions of TextMate aren’t supported on Mavericks. The file will be named “nightly”; save it to your desktop. Once the “nightly” file has finished downloading, rename it to “TextMate.app.tar.bz2” — that will give it the “BZ” icon on your desktop. Once it’s been renamed, you can double-click on it, and TextMate.app will appear on your desktop. Use your administrative login to move TextMate.app to your Applications folder.
    Regarding the “unidentified developer” message displayed by trying to open git 1.8.4.2, please refer to this Apple page for the workaround.

  • How do I convert mail merge documents to individual pdf docs and save each with a field in the merge?

    How do I convert mail merge documents to individual pdf docs and save each with a field in the merge?

    Is this an actual field, or just some piece of static text somewhere? Either way, you can't do it using the Split Document command. You'll need to use a custom-made script to read the value of this "field" and use it when extracting pages from the file.

  • What is the difference between the following cases... ?

    What is the symbol *%2 %3 %4 %5 %6 %7* used for?
    What is the difference between the following cases about the symbol *%2 %3 %4 %5 %6 %7* ?
    Case 1:
    "%NEW_JAVA_HOME%"\bin\java %COH_OPTS% -Xms1g -Xmx1g com.tangosol.net.DefaultCacheServer
    %2 %3 %4 %5 %6 %7Case 2:
    com.tangosol.examples.%EXAMPLE%.Driver contacts %EXAMPLES_DIR%\..\resource\contacts.csv
    %2 %3 %4 %5 %6 %7Thank you

    It just passes whatever else was on the command line to the "java" command. So if you have a Windows test.cmd file that looks like this:
    java %1 %2 %3 %4 %5 %6 %7Then you can pretty much use "test" anywhere you would use "java", because it passes through its command line parameters (or at least up to 7 of them).
    Peace,
    Cameron Purdy | Oracle Coherence

  • What do the upgrade scripts do for the following cases?

    Hi,
    I have got the compare reports between 9.0 vanilla(Source) and 8.4 copy of production(Target).
    it has the following properties.
    source---------target--------action-----upgrade
    changed-----*changed-------copy-------yes
    changed-----*unchanged----copy-------yes
    unchanged---*changed------copy--------yes
    unchanged----*unchanged--copy--------yes
    which means in all the above cases the customizations will be overridden.
    I have read somewhere that as a developer i need to look for the following case and re-apply the customizations
    source---------target--------action-----upgrade
    changed-----*changed-------copy-------yes
    my question is that, when we run the 9.0 upgrade scripts on 8.4 copy of production, will it not override the customizations for the following cases?
    source---------target--------action-----upgrade
    unchanged---*changed------copy--------yes
    unchanged----*unchanged--copy--------yes
    Please help me,
    Thank you.
    Edited by: user609854 on Dec 8, 2008 6:20 PM

    If you are talking about compare reports during Initial move of Upgrade --Yes , objects from the source will come over and based on user's or you(in this case) have to re-apply them back.At later stages of the upgrade pass  you have to re-apply them eventually if you want to opt with old or delivered custom or pure custom psoft objects.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • When upgrading to the most current version of iTunes I get the following error message "An application has made an attempt to load the C runtime library incorrectly"  How do I fix this?

    When upgrading iTunes I recieve the following error message "An application has made an attempt to load the C runtime library incorrectly". 
    Program:C:\Program Files\iTunes.exe

    See Troubleshooting issues with iTunes for Windows updates.
    tt2

  • How to ''give'' error for this case of an EXTERNAL TABLE?

    Our external table routine works fine:
    -- We have a csv file with 2 cols.
    -- When we create the table referring the csv it works fine.
    -- Even if the csv has more the 2 cols, the ET command only takes the 2 cols and it works fine.
    -- Now, users are saying that if the csv has more than 2 cols, the ET command should give an error
    I went through the command but cannot find any clause which will do this.
    Is there any other way or workaround?
    CREATE TABLE <table_name> (
    <column_definitions>)
    ORGANIZATION EXTERNAL
    (TYPE oracle_loader
    DEFAULT DIRECTORY <oracle_directory_object_name>
    ACCESS PARAMETERS (
    RECORDS DELIMITED BY newline
    BADFILE <file_name>
    DISCARDFILE <file_name>
    LOGFILE <file_name>
    [READSIZE <bytes>]
    [SKIP <number_of_rows>
    FIELDS TERMINATED BY '<terminator>'
    REJECT ROWS WITH ALL NULL FIELDS
    MISSING FIELD VALUES ARE NULL
    (<column_name_list>))\
    LOCATION ('<file_name>'))
    [PARALLEL]
    REJECT LIMIT <UNLIMITED | integer>;
    Is it possible to use the READSIZE?
    Edited by: Channa on Sep 23, 2010 2:28 AM

    -- Now, users are saying that if the csv has more than 2 cols, the ET command should give an error
    I went through the command but cannot find any clause which will do this.
    Is there any other way or workaround?I looked at Serverprocess' sql*loader script and did not see how that would answer your question - how to raise an error if the file has more than 2 columns. If I missed something can Serverprocess explain?
    I can't think of a direct way to do this with your external table either, but there may be indirect ways. Some brainstorming ideas of perhaps dubious usefulness follow.
    Placing a view over the external table can limit results to the first two columns but won't raise an error.
    A pipelined function can read the external table, check for data where there shouldn't be any, and raise an exception when you find data in columns where there should not be any.
    Similarly, you could ditch the external table and use utl_file to read the file, manually parsing and checking the data. LOTS more work but more control on your end. External tables are much easer to use :(
    Or, first load the external table into a work table before the "real" select. Check the work table for the offending data programatically and raise an error if data is where it should not be. You could keep the existing external table and not have to do a lot of recoding.
    Or, also load the data into an otherwise unneeded global temporary table first. Use a trigger on the load to look for the unwanted data and raise an error if offending data is there
    These ideas are boiling down to variations on validating the data before you use it.
    Good luck!

  • How to set border lines in table and also in template in the smartforms ?

    How to set border lines in table and also in template in the smartforms ?
    As I have to create table with following detals
    total row = 3
    row1 = 3 column
    row2 = 6 column
    row3 = 9 column
    for 2nd and 3rd row data to be fetched using coding.
    so can anybody explain me what should i use
    Table or Template ?
    and I want the border like excel format.
    Can anybody suggest me ?
    Thanks
    naresh

    if the data is multiple i.e. line items choose table.
    if the data is single i.e. fixed choose template.
    Create table
    >  Draw u r no lines
    > choose option select pattern
    > select display framed patterns
    Choose u r required one.
    out lined, or full lined. u can choose option.
    same procedure to be followed for template also.
    with regards,
    Kiran.G

  • How to fix this error "this iPad is not able to complete the activation process. Please press Home and start over. If the issue persists, please visit your nearest Apple Store or Authorized service provider for more information or replacement"?

    How to fix this error "this iPad is not able to complete the activation process. Please press Home and start over. If the issue persists, please visit your nearest Apple Store or Authorized service provider for more information or replacement"? When I plugged in my iPad this popped up!

    Hi csreddy, 
    If you are receiving a message to contact an Apple Retail Store or Authorized Service Provider for help updating from iOS 3, click on the link below to initiate that support:
    Update the iOS software on your iPhone, iPad, and iPod touch - Apple Support
    http://support.apple.com/en-us/HT204204
    Update your device using iTunes
    If you can’t update wirelessly, or if you want to update with iTunes, follow these steps:
    Install the latest version of iTunes on your computer.
    Plug in your device to your computer.
    In iTunes, select your device.
    In the Summary pane, click Check for Update. 
    Click Download and Update.
    If you don't have enough free space to update using iTunes, you'll need to delete content manually from your device.
    Find out what to do if you get other error messages while updating your device.
    Last Modified: Jan 12, 2015
    Apple - Find Locations
    https://locate.apple.com
    Contact Apple for support and service - Apple Support
    http://support.apple.com/en-us/HT201232
    Regards,
    - Judy

Maybe you are looking for