I'm trying to use the Oracle NVL() function to replace NULL with "N/A":
SELECT ID AS "Record ID",
( SELECT NVL( COMMENT , "N/A") FROM CHECKBOX WHERE ( B1_CHECKBOX_DESC = 'Solar KW' ) AND ( RECORDS.ID1 = CHECKBOX.ID1 AND RECORDS.ID3 = CHECKBOX.ID3 ) ) AS "Solar",
( SELECT NVL( COMMENT, "N/A" ) FROM CHECKBOX WHERE ( B1_CHECKBOX_DESC = 'Code Edition' ) AND ( RECORDS.ID1 = CHECKBOX.ID1 AND RECORDS.ID3 = CHECKBOX.ID3 ) ) AS "Coder"
FROM RECORDS
Note: I'm trying to replace NULL with "N/A," not an empty string, so it should work. However, in the result set, I'm still getting NULL values instead of "N/A". What am I doing wrong?
Just wrong place for NVL(), not that your subqueries may not return rows, so use NVL on subquery:
SELECT ID AS "Record ID",
NVL(
( SELECT "COMMENT" FROM CHECKBOX WHERE B1_CHECKBOX_DESC = 'Solar KW'
AND RECORDS.ID1 = CHECKBOX.ID1 AND RECORDS.ID3 = CHECKBOX.ID3 )
, 'N/A') AS "Solar",
NVL(
( SELECT "COMMENT" FROM CHECKBOX WHERE B1_CHECKBOX_DESC = 'Code Edition'
AND RECORDS.ID1 = CHECKBOX.ID1 AND RECORDS.ID3 = CHECKBOX.ID3 )
, 'N/A' ) AS "Coder"
FROM RECORDS
But probably it would be better to use lateral or outer apply here:
SELECT
ID AS "Record ID",
c.*
FROM RECORDS
outer apply(
SELECT
nvl(solar,'N/A') as solar,
nvl(coder,'N/A') as coder
FROM (select *
from CHECKBOX
WHERE B1_CHECKBOX_DESC in ('Solar KW' , 'Code Edition')
AND RECORDS.ID1 = CHECKBOX.ID1
AND RECORDS.ID3 = CHECKBOX.ID3
)
pivot(
max("COMMENT")
for B1_CHECKBOX_DESC in (
'Solar KW' as Solar,
'Code Edition' as Coder
)
)
) c
Full example with test data:
DBFiddle
with
records(id,id1,id3) as (
select 1,1,1 from dual union all
select 2,2,2 from dual
)
,CHECKBOX("COMMENT",id1,id3,B1_CHECKBOX_DESC) as (
select 'comment1-1',1,1, 'Solar KW' from dual union all
select 'comment1-2',1,1, 'Code Edition' from dual union all
select 'comment2-1',2,2, 'Solar KW' from dual
)
SELECT
ID AS "Record ID",
c.*
FROM RECORDS
outer apply(
SELECT
nvl(solar,'N/A') as solar,
nvl(coder,'N/A') as coder
FROM (select *
from CHECKBOX
WHERE B1_CHECKBOX_DESC in ('Solar KW' , 'Code Edition')
AND RECORDS.ID1 = CHECKBOX.ID1
AND RECORDS.ID3 = CHECKBOX.ID3
)
pivot(
max("COMMENT")
for B1_CHECKBOX_DESC in (
'Solar KW' as Solar,
'Code Edition' as Coder
)
)
) c;
Results:
Record ID SOLAR CODER
---------- ---------- ----------
1 comment1-1 comment1-2
2 comment2-1 N/A
Related
Trying to get my head around this but I am stumped. Can I use an IIf with a HAVING statement or a CASE?
My current SQL is this:
SELECT dbo_forecast.mtl_part_part_nbr,
SUM(Round(dbo_forecast.forecast_qty)) AS FCST,
dbo_m8stacd_standards.whse_nbr,
dbo_m8stacd_standards.statn_cd,
dbo_m8stacd_standards.prty
INTO tblforecast77
FROM dbo_m8stacd_standards
INNER JOIN dbo_forecast
ON dbo_m8stacd_standards.part_nbr =
dbo_forecast.mtl_part_part_nbr
WHERE ( ( ( dbo_forecast.type ) = 11
OR ( dbo_forecast.type ) = 12 )
AND ( ( dbo_forecast.forecast_month ) = '01'
OR ( dbo_forecast.forecast_month ) = '02'
OR ( dbo_forecast.forecast_month ) = '03'
OR ( dbo_forecast.forecast_month ) = '04'
OR ( dbo_forecast.forecast_month ) = '05'
OR ( dbo_forecast.forecast_month ) = '06'
OR ( dbo_forecast.forecast_month ) = '07'
OR ( dbo_forecast.forecast_month ) = '08'
OR ( dbo_forecast.forecast_month ) = '09'
OR ( dbo_forecast.forecast_month ) = '10'
OR ( dbo_forecast.forecast_month ) = '11'
OR ( dbo_forecast.forecast_month ) = '12' ) )
GROUP BY dbo_forecast.mtl_part_part_nbr,
dbo_m8stacd_standards.whse_nbr,
dbo_m8stacd_standards.statn_cd,
dbo_m8stacd_standards.prty
HAVING ( ( ( dbo_forecast.mtl_part_part_nbr ) = "00104918" )
AND ( ( dbo_m8stacd_standards.whse_nbr ) = 77 )
AND ( ( dbo_m8stacd_standards.prty ) = "01"
OR ( dbo_m8stacd_standards.prty ) = "d" )
AND ( ( SUM(Round([dbo_forecast].[forecast_qty])) ) > 0 ) );
And returns this:
What I want to return is if there is a "D" in prty (for that part number) return the FCST for that, if there is not a prty (for that part number) D return the FCST for prty = "01"
edit: Sorry I should have worded this better. What I want is return one record. The prty=d record if it exists, otherwise the 01 record.
How can get totalizations out of a group, especifically in Firebird 2.5.
I have the following query, it's big but it's simple, it has only some inner joins that are correlated.
SELECT "patrimônio", porc_residual AS "percentual residual", vida_util AS "vida útil",
vida_util_meses "vida útil meses", valor_base AS "valor aquisição/valor reavaliação",
"data de incorporação", VALOR_DEPRECIADO AS "valor depreciado" ,
grupo_audesp AS "grupo contábil", sum(dt_depreciado) over(ORDER BY grupo_audesp ) td
FROM
(
SELECT m.nome AS "patrimônio", t.PORC_RESIDUAL, t.VIDA_UTIL, t.VIDA_UTIL_MESES,
lpad(EXTRACT(DAY FROM t.dt_cadastro),2, '0') || '/' || lpad(EXTRACT(month FROM t.dt_cadastro),2, '0') || '/' || EXTRACT(year FROM t.dt_cadastro) "data de incorporação"
,t.placa, GA.ID_AUDESP, GA.NOME AS GRUPO_AUDESP,
T.VALOR as valor,
CASE WHEN (SELECT min(D.VALOR_NOVO)
FROM patrimonio_depreciacao D WHERE D.id_tombamento = T.id_tombamento
AND T.ID_ORGAO = '030000' AND T.SITUACAO IN('A','B')
AND D.REFERENCIA2 >=202201 AND D.REFERENCIA2 <=202201 ) IS NULL THEN(
case when (select max(d.valor_anterior)
from patrimonio_depreciacao D where D.id_tombamento = T.id_tombamento and
T.SITUACAO IN('A','B')
AND d.referencia2 >202201 ) IS NULL THEN T.VALOR_ATUAL ELSE
(select max(d.valor_anterior)
from patrimonio_depreciacao D where D.id_tombamento = T.id_tombamento and
T.SITUACAO IN('A','B')
AND d.referencia2 >202201 )
END)
ELSE
(SELECT min(D.VALOR_NOVO)
FROM patrimonio_depreciacao D WHERE D.id_tombamento = T.id_tombamento
AND T.ID_ORGAO = '030000' AND T.SITUACAO IN('A','B')
AND D.REFERENCIA2 >=202201 AND D.REFERENCIA2 <=202201 ) END as valor_atual,
(SELECT sum(D.VALOR_DEPRECIADO)
FROM patrimonio_depreciacao D WHERE D.id_tombamento = T.id_tombamento
AND T.ID_ORGAO = '030000'
AND D.REFERENCIA2 >=202201 AND D.REFERENCIA2 <=202201 ) as valor_depreciado, T.DT_AQUISICAO,
PS.NOME,
case when (select first 1 pri.vl_reavaliacao from patrimonio_reavaliacao_item pri
inner join patrimonio_reavaliacao pr on pr.id_reavaliacao = pri.id_reavaliacao_item
where pri.id_tombamento = t.id_tombamento
and pr.data<='2022-01-31'
and pr.encerrado ='S'
order by pr.data desc) is null then t.vl_base_depreciacao
else
(select first 1 pri.vl_reavaliacao from patrimonio_reavaliacao_item pri
inner join patrimonio_reavaliacao pr on pr.id_reavaliacao = pri.id_reavaliacao_item
where pri.id_tombamento = t.id_tombamento
and pr.data <= '2022-01-31'
and pr.encerrado ='S'
order by pr.data desc) end as valor_base
FROM PATRIMONIO_TOMBAMENTO T
LEFT JOIN PATRIMONIO_GRUPO_AUDESP GA ON GA.ID_GRUPO_AUDESP = T.ID_GRUPO_AUDESP
LEFT JOIN ESTOQUE_MATERIAL M ON M.ID_MATERIAL = T.ID_MATERIAL
LEFT JOIN PATRIMONIO_SETOR PS ON (T.ID_SETOR = PS.ID_SETOR)
WHERE T.ID_ORGAO = '030000'
AND (T.SITUACAO IN('A') or ( T.SITUACAO = 'B' AND T.DT_BAIXA >'2022-01-31'))
AND (T.DT_REATIVADO IS NULL OR T.DT_REATIVADO<= '2022-01-31' or (T.DT_BAIXA >'2022-01-31'))
AND T.dt_cadastro <= '2022-01-31'
AND PS.TIPO_SETOR = 'S'
ORDER BY GA.ID_AUDESP, t.DT_CADASTRO) t
I think most import is the result
I want to sum "valor depreciado" and "valor aquisição/valor reavaliação" based on those groups.
to make it simple it could be an additional column that repeats the sum in all rows for the entire group.
I have a view from the view need to fetch some result set for that purpose I have wrote following query.
So here the problem is stuff with xml is taking so much time any suggestions please.
;WITH CTE_transaction_type1 AS
(
SELECT case_summary_id,Primary_Payer, Physician,Generate_Bill,
CASE
WHEN Current_Payer IS NULL
THEN CASE
WHEN Resposible_Patient_Name IS NULL
AND PG_Patient_Name IS NULL
THEN 'PG:' + Patient_Last_Name + ',' + Patient_First_Name
WHEN Resposible_Patient_Name IS NULL
AND NULLIF(PG_Patient_Name,' ') IS NOT NULL
THEN 'SG:' + Patient_Last_Name + ',' + Patient_First_Name
ELSE Resposible_Patient_Name
END
ELSE
CASE
WHEN Current_Payer_Name IS NULL
THEN ''
ELSE Insurance_Type + Current_Payer_Name + IIF(Plan_Name IS NULL, '', ',' + Plan_Name)
END
END AS Responsible_Party_List
FROM [charts].[vw_billing_analysis]
WHERE sort_order = 0 AND transaction_type_id = 1
)
SELECT ba.Case_Summary_ID
,ba.date_of_surgery
,ba.Organization_ID
,ba.Organization_Name
,ba.Patient_Name
,ba.Patient_First_Name
,ba.Patient_Last_Name
,ba.MRN
,ba.Physician_ID
,ba.Physician
,ba.[PROCEDURE]
,ba.Current_Payer
,ba.Current_Payer_Name
,ba.Primary_Payer
,ba.Primary_Payer_ID
,ba.Insurance_Plan_ID
,ba.Insurance_Plan_Type
,ba.Plan_Name
,ba.Speciality_ID
,ba.Speciality_Name
,ba.Transaction_Responsible_Party_ID
,ba.Charge_ID
,ba.Charge_Procedure_ID
,ba.Patient_Insurance_ID
,ba.Insurance_Type
,ba.Resposible_Patient_Name
,ba.Received_From
,ba.Guarantor_Master_ID
,ba.PG_Patient_Name
,ba.Batch_Description
,ba.Period_Name
,ba.Unassigned_payment
,ba.Charge
,ba.Charge_Corr
,ba.Debit
,ba.Payments
,ba.WriteOff
,ba.Balance
,ba.Corrected_TF
,ba.Period_ID
,ba.Batch_ID
,ba.transaction_type_id
,STUFF((
SELECT '; ' + [Procedure]
FROM [charts].[vw_billing_analysis] vba
WHERE vba.case_summary_id = ba.case_summary_id
AND vba.transaction_type_id = 1
ORDER BY ba.sort_order
FOR XML PATH('')
,TYPE
).value('.', 'NVARCHAR(MAX)'), 1, 2, '') AS Procedure_List
,trty1.Primary_Payer AS Primary_Payer_List
,trty1.Responsible_Party_List
,trty1.Physician AS Physician_List
,ba.Allowed_Amount
,IIF(ba.insurance_contract_id IS NULL
OR ba.Insurance_Plan_Type = 'Self-Pay', NULL, iif(ba.procedure_type IS NOT NULL, round(ba.[allowed_amount] - (ba.[allowed_amount] * ba.procedure_discount / 100.0), 3), ba.[procedure_amount])) AS [Expected_Amount]
,ba.Procedure_Amount
,ba.Generate_Bill
,trty1.Generate_Bill AS Generate_Bill_Case
,ba.Actual_Payment
,ba.First_Bill_Date
FROM [charts].[vw_billing_analysis] ba
left join cte_transaction_type1 trty1
ON ba.Case_Summary_ID=trty1.Case_Summary_ID
WHERE ba.Organization_ID =52
AND
(
(
(
(
ba.Period_Id = ('999999999')
OR '999999999' = '999999999'
)
AND 0 = 1
)
AND (
(
ba.Batch_Id IN ('999999999')
OR '999999999' = '999999999'
)
AND 0 = 1
)
)
OR (
0 = 0
AND ba.date_of_surgery >= '2018-02-01'
AND ba.date_of_surgery <= '2021-03-03'
)
)
AND (
CASE
WHEN ba.Insurance_Plan_Type IS NULL
AND ba.Insurance_Plan_ID IS NULL
AND ba.Current_Payer IS NULL
THEN '-1'
ELSE ba.Insurance_Plan_Type_Id
END IN ('999999999')
OR '999999999' = '999999999'
)
AND (
ba.Current_Payer IN ('999999999')
OR '999999999' = '999999999'
)
AND (
ba.Speciality_ID IN ('999999999')
OR '999999999' = '999999999'
)
AND (
ba.Physician_ID IN ('999999999')
OR '999999999' = '999999999'
)
AND (
isnull(ba.Primary_Payer_ID, - 1) IN ('999999999')
OR '999999999' = '999999999'
)
AND (
ba.appointment_type_id IN ('999999999')
OR '999999999' = '999999999'
)
AND (
SELECT SUM(CASE
WHEN vba.transaction_type_id = 1
THEN balance
WHEN vba.transaction_type_id = 3
THEN - balance
END)
FROM [charts].[vw_billing_analysis] vba
WHERE vba.case_summary_id = ba.case_summary_id
) >= 0
ORDER BY ba.Date_Of_Surgery DESC
,ba.MRN DESC
,ba.Patient_Name ASC
,ba.upd_tr_sort ASC
,ba.Sort_Order ASC
My query
SELECT DISTINCT dbo.tblacc_cv.cv_docno,
dbo.tblacc_cv.cv_docdate,
dbo.tblacc_cv.cv_suppliername,
dbo.tblacc_cv.cv_extdocno,
dbo.tblacc_chartaccount.coa_cvtype AS cvtype,
dbo.tblacc_glentry.gl_accountid,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '201001' THEN Sum(
dbo.tblacc_glentry.gl_credit)
ELSE NULL
END ) AS AP,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '208000' THEN Sum(
dbo.tblacc_glentry.gl_amount)
ELSE NULL
END ) AS EWT,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '616000'
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS FABpur,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '603000'
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS FABcre,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '602000'
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS RawMat,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid = '601003'
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS PurCre,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid NOT IN (
'201001', '208000', '616000', '603000',
'602000', '601003' ) THEN
dbo.tblacc_glentry.gl_accountname
ELSE NULL
END ) AS GL_AccountName,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid NOT IN (
'616000', '603000', '602000', '601003'
)
AND dbo.tblacc_chartaccount.coa_cvtype = 'M' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS MOdr,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid NOT IN (
'616000', '603000', '602000', '601003'
)
AND dbo.tblacc_chartaccount.coa_cvtype = 'F' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS FDR,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid NOT IN (
'201001', '208000', '616000', '603000',
'602000', '601003' )
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_debit)
ELSE NULL
END ) AS SunDR,
( CASE
WHEN dbo.tblacc_glentry.gl_accountid NOT IN (
'201001', '208000', '616000', '603000',
'602000', '601003' )
AND dbo.tblacc_chartaccount.coa_cvtype = 'S' THEN Sum(
dbo.tblacc_glentry.gl_credit)
ELSE NULL
END ) AS SunCR
FROM dbo.tblacc_glentry
INNER JOIN dbo.tblacc_apv
ON dbo.tblacc_glentry.gl_docno = dbo.tblacc_apv.apv_docno
INNER JOIN dbo.tblacc_cv
INNER JOIN dbo.tblacc_cvdetail
ON dbo.tblacc_cv.cv_docno =
dbo.tblacc_cvdetail.cvd_cv_docno
ON dbo.tblacc_apv.apv_docno = dbo.tblacc_cvdetail.cvd_refdocno
INNER JOIN dbo.tblacc_chartaccount
ON dbo.tblacc_glentry.gl_accountid =
dbo.tblacc_chartaccount.coa_account_id
WHERE ( dbo.tblacc_cv.cv_docdate BETWEEN
'01/01/2018 00:00:00' AND '1/30/2018 23:59:59' )
GROUP BY dbo.tblacc_cv.cv_docno,
dbo.tblacc_cv.cv_docdate,
dbo.tblacc_cv.cv_suppliername,
dbo.tblacc_glentry.gl_accountname,
dbo.tblacc_cv.cv_extdocno,
dbo.tblacc_chartaccount.coa_cvtype,
dbo.tblacc_glentry.gl_accountid,
dbo.tblacc_glentry.gl_credit,
dbo.tblacc_glentry.gl_amount,
dbo.tblacc_glentry.gl_debit
ORDER BY dbo.tblacc_cv.cv_docdate ASC
Sample Output
Desired Ouput
Your desired output is not an example of a PIVOT.
Lacking a detailed explanation of your logic, I can tell you that you can get your desired output by GROUPing BY the first four columns, and applying MAX() to all the others. (Except cvtype which would be a MIN).
I'm new to SQL and I'm trying to group a set of remarks that is spread over several rows. Specifically I want to aggregate the RMK_TEXT column and order by RMK_LINENO.
Can anyone help me out?
SELECT
ALL_AGREEMENTS.AGMT_NUM,
PROVISION_TYPES.STIP_TYPE_DESC,
GENERAL_REMARK_TEXT.RMK_LINENO,
LISTAGG(GENERAL_REMARK_TEXT.RMK_TEXT) WITHIN GROUP (ORDER BY GENERAL_REMARK_TEXT.RMK_LINENO) RMK_TEXT
FROM
STIPULATION_PROVISIONS,
ALL_AGREEMENTS,
STIPULATION_TYPES PROVISION_TYPES,
GENERAL_REMARK_TEXT,
GENERAL_REMARKS
WHERE
( ALL_AGREEMENTS.ARRG_KEY=STIPULATION_PROVISIONS.ARRG_KEY(+) )
AND ( STIPULATION_PROVISIONS.STIP_TYPE_CODE=PROVISION_TYPES.STIP_TYPE_CODE(+) )
AND ( PROVISION_TYPES.STIP_CATG_CODE = 'PRV' )
AND ( GENERAL_REMARKS.GEN_RMK_FK(+)=STIPULATION_PROVISIONS.STIP_KEY AND GENERAL_REMARKS.RMK_TYPE_CATG(+) = 'PRV' )
AND ( GENERAL_REMARKS.RMK_KEY = GENERAL_REMARK_TEXT.RMK_KEY(+) )
AND ( GENERAL_REMARKS.RMK_TYPE_CATG (+) = 'PRV' )
AND ( ( ALL_AGREEMENTS.ARRG_ORG_KEY IN
(SELECT ARRG_ORG_KEY
FROM BO_USER_DATA_PRIVS
WHERE OBJECT_TYPE_CD = 'area'
AND SEC_USER_ID = UPPER('user'))
AND ALL_AGREEMENTS.SUBJ_CODE IN
(SELECT SUBJ_CODE
FROM BO_USER_DATA_PRIVS
WHERE OBJECT_TYPE_CD = 'SUBJ'
AND SEC_USER_ID = UPPER('user')) ) )
AND
(
(
ALL_AGREEMENTS.AGMT_NUM IN ( '00003000','00004000','00005001','00005002','00005003','00006000','00007000','00008000','00009000','00010000','00021000','00022000','00023000','00024000','00025000','00026000' )
)
AND
PROVISION_TYPES.STIP_TYPE_DESC IN ( 'provision' )
AND
STIPULATION_PROVISIONS.EXST_FLAG IN ( 'Y' )
)
GROUP BY ALL_AGREEMENTS.AGMT_NUM
Something like this:
SELECT
a.AGMT_NUM,
p.STIP_TYPE_DESC,
s.EXST_FLAG,
( SELECT LISTAGG( t.RMK_TEXT, CHR(13) || CHR(10) )
WITHIN GROUP ( ORDER BY t.RMK_LINENO )
FROM GENERAL_REMARKS r
INNER JOIN GENERAL_REMARK_TEXT t
ON ( r.RMK_KEY = t.RMK_KEY)
WHERE r.GEN_RMK_FK = s.STIP_KEY
AND r.RMK_TYPE_CATG = 'PRV'
) AS Remarks
FROM
ALL_AGREEMENTS a
LEFT OUTER JOIN STIPULATION_PROVISIONS s
ON ( a.ARRG_KEY = s.ARRG_KEY )
LEFT OUTER JOIN STIPULATION_TYPES p
ON ( s.STIP_TYPE_CODE = p.STIP_TYPE_CODE )
WHERE
p.STIP_CATG_CODE = 'PRV'
AND EXISTS ( SELECT 1
FROM BO_USER_DATA_PRIVS b
WHERE OBJECT_TYPE_CD = 'LAND'
AND SEC_USER_ID = UPPER('user')
AND a.ARRG_ORG_KEY = b.ARRG_ORG_KEY
)
AND EXISTS ( SELECT 1
FROM BO_USER_DATA_PRIVS b
WHERE OBJECT_TYPE_CD = 'SUBJ'
AND SEC_USER_ID = UPPER('user')
AND a.SUBJ_CODE = b.SUBJ_CODE
)
AND a.AGMT_NUM IN ( 'OH00003000','OH00004000','OH00005001','OH00005002','OH00005003','OH00006000','OH00007000','OH00008000','OH00009000','OH00010000','OH00021000','OH00022000','OH00023000','OH00024000','OH00025000','OH00026000' )
AND p.STIP_TYPE_DESC = 'provision'
AND s.EXST_FLAG = 'Y';