------Load Dataset into Temp table--------------- SELECT z.SYSTEMNAME --,Case when ZXC.[Subsystem Name] <> 'NULL' Then zxc.[SubSystem Name] --else NULL --End AS SubSystemName , CASE WHEN z.PROV_TAX_ID IN (SELECT DISTINCT zxc.TIN FROM dbo.SQS_Provider_Tracking zxc WHERE zxc.[SubSystem Name] <> 'NULL' ) THEN (SELECT DISTINCT [Subsystem Name] FROM dbo.SQS_Provider_Tracking zxc WHERE z.PROV_TAX_ID = zxc.TIN) End As SubSYSTEMNAME ,z.PROVIDERNAME ,z.STATECODE ,z.PROV_TAX_ID ,z.SRC_PAR_CD ,SUM(z.SEQUEST_AMT) Actual_Sequestered_Amt --------------------------------------------------------------------------------- , CASE WHEN z.SRC_PAR_CD IN ('E','O','S','W') THEN 'Nonpar Waiver' --**Amendment Mailed** --WHEN z.PROV_TAX_ID IN When EXISTS (SELECT DISTINCT b.PROV_TIN FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK ) where not exists (select * from dbo.sqs_objector_TINs t where b.PROV_TIN = t.prov_tin)) THEN (SELECT DISTINCT b.Mailing FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK ) WHERE z.PROV_TAX_ID = b.PROV_TIN ) -- --**Amendment Mailed Wave 3 and 4** --WHEN z.PROV_TAX_ID In When EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Amendment Mailed (3rd Wave)' and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin)) THEN 'Amendment Mailed (3rd Wave)' WHEN EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Amendment Mailed (4th Wave)' and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin)) THEN 'Amendment Mailed (4th Wave)' -- --Is Puerto Rico of Lifesynch WHEN EXISTS (SELECT DISTINCT a.PROV_TAX_ID FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK ) WHERE a.Bucket <> 'Nonpar' ) THEN (SELECT DISTINCT a.Bucket FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK ) WHERE a.PROV_TAX_ID = z.PROV_TAX_ID) -- --**Top Objecting Systems** WHEN z.SYSTEMNAME IN ('ADVENTIST HEALTH SYSTEM','ASCENSION HEALTH ALLIANCE','AULTMAN HEALTH FOUNDATION','BANNER HEALTH SYSTEM','BERT FISH MEDICAL CENTER','BETHESDA MEMORIAL HOSPITAL','BJC HEALTHCARE','BLOUNT MEMORIAL HOSPITAL','BOCA RATON REGIONAL HOSPITAL','CAROMONT HEALTH SYSTEM','CATHOLIC HEALTH INITIATIVES','CATHOLIC HEALTHCARE PARTNERS','CHRISTUS HEALTH',/*'CLEVELAND CLINIC HEALTH SYSTEM',*/'COLUMBUS REGIONAL HEALTHCARE SYSTEM','COMMUNITY HEALTH SYSTEMS, INC','COXHEALTH','HCA','HEALTH MANAGEMENT ASSOCIATES','HUNTSVILLE HOSPITAL HEALTH SYSTEM','INTEGRIS HEALTH','JUPITER MEDICAL CENTER','LEE MEMORIAL HEALTH SYSTEM','MARTIN MEMORIAL HEALTH SYSTEM','MERCY','MT SINAI MEDICAL CENTER (MIAMI)','MUNROE REGIONAL MEDICAL CENTER','NORMAN REGIONAL HEALTH SYSTEM','NORTHSIDE HEALTH SYSTEM','SHANDS HEALTHCARE','SISTERS OF MERCY - SPRINGFIELD, MO','SSM HEALTH CARE','ST LUKES HEALTH SYSTEM','SUMMA HEALTH SYSTEM','SUSQUEHANNA HEALTH SYSTEM','TBD -- TRINITY HEALTH - CATHOLIC HEALTH EAST','UNIVERSITY OF MISSOURI HEALTH SYSTEM','UNIVERSITY OF NEW MEXICO HOSPITALS','UNIVERSITY OF UTAH HEALTH CARE') THEN 'Top Objecting Systems' WHEN EXISTS (SELECT h.PROV_TAX_ID FROM #HIHO_Records h INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK ) ON h.PROV_TAX_ID = obj.TIN AND obj.[Objector?] = 'Top Objector' WHERE z.PROV_TAX_ID = h.PROV_TAX_ID OR h.SMG_ID IS NOT NULL )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI') THEN 'Top Objecting Systems' -- --**Other Objecting Hospitals** WHEN EXISTS (SELECT h.PROV_TAX_ID FROM #HIHO_Records h INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK ) ON h.PROV_TAX_ID = obj.TIN AND obj.[Objector?] = 'Objector' WHERE z.PROV_TAX_ID = h.PROV_TAX_ID OR h.SMG_ID IS NOT NULL )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI') THEN 'Other Objecting Hospitals' -- --**Objecting Physicians** WHEN EXISTS (SELECT z.PROV_TAX_ID FROM SQS_EDW_Source z WITH (NOLOCK) WHERE EXISTS (SELECT DISTINCT obj.TIN FROM SQS_Provider_Tracking obj WITH (NOLOCK ) WHERE obj.[Objector?] in ('Objector','Top Objector') and z.PROV_TAX_ID = obj.TIN ) and z.LCLM_RSTMT_TREND_CAT_CD not IN ('HO','HI') ) THEN 'Objecting Physicians' --****Rejecting Hospitals**** WHEN EXISTS (SELECT h.PROV_TAX_ID FROM #HIHO_Records h INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK ) ON h.PROV_TAX_ID = obj.TIN AND obj.[Objector?] = 'Rejector' WHERE z.PROV_TAX_ID = h.PROV_TAX_ID OR h.SMG_ID IS NOT NULL )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI') THEN 'Rejecting Hospitals' --****Rejecting Physciains**** WHEN EXISTS (SELECT obj.TIN FROM SQS_Provider_Tracking obj WITH (NOLOCK ) WHERE z.PROV_TAX_ID = obj.TIN AND obj.[Objector?] = 'Rejector') and z.LCLM_RSTMT_TREND_CAT_CD NOT IN ('HO','HI') THEN 'REjecting Physicians' ----**********ALL OBJECTORS SHOULD HAVE BEEN BUCKETED AT THIS POINT IN THE QUERY********** -- --**Non-Objecting Hospitals** WHEN EXISTS (SELECT DISTINCT h.PROV_TAX_ID FROM #HIHO_Records h WITH (NOLOCK ) WHERE (z.PROV_TAX_ID = h.PROV_TAX_ID) OR h.SMG_ID IS NOT NULL )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI') THEN 'Non-Objecting Hospitals' -- **Outstanding Contracts for Review** WHEN EXISTS (SELECT qz.PROV_TIN FROM [PACT].[HUMAD\ARS3766].[SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Non-Objecting Bilateral Physicians' AND z.PROV_TAX_ID = qz.PROV_TIN) Then 'Non-Objecting Bilateral Physicians' When EXISTS (select p.prov_tax_id from dbo.SQS_CoC_Potential_Mail_List p WITH (NOLOCK ) where p.amendmentrights <> 'Unilateral' AND z.prov_tax_id = p.prov_tax_id) THEN 'Non-Objecting Bilateral Physicians' WHEN EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'More Research Needed' AND qz.PROV_TIN = z.PROV_TAX_ID) THEN 'More Research Needed' WHEN EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Objector' AND qz.PROV_TIN = z.PROV_TAX_ID) THEN 'ERROR' else 'Market Review/Preparing to Mail' END AS [Updated Bucket] -------------------------------------------------------------------------- ,COALESCE(q.INDdesc, f.IND_desc) AS INDdesc ,f.Time_Period_for_Dispute ,f.Renew_Term_Ind ,f.Renewal_Date ,z.SMG_ID ,'' AS OrderedRank INTO SQS_Bucketed_Details_SMG_on_SMGXXX From #SQS_EDW_SOURCE_WithSMG z left join #F f ON f.PROV_TAX_ID = z.PROV_TAX_ID AND z.SYSTEMNAME = f.SYSTEM_NAME AND z.PROVIDERNAME = f.Provider Left join #Q q ON z.PROV_TAX_ID = q.TIN GROUP BY z.SYSTEMNAME --,Z.[SubsystemName] ,z.PROVIDERNAME ,z.STATECODE ,z.PROV_TAX_ID ,z.SRC_PAR_CD ,q.INDdesc ,f.IND_Desc ,f.Time_Period_for_Dispute ,f.Renew_Term_Ind ,f.Renewal_Date ,z.SMG_ID ,z.LCLM_RSTMT_TREND_CAT_CDAs I am a developer I do not have the access to Sql profiler or tuning agent to optimize my query, I have used some joins over the temp table #HIHO which indeed pulling the records from table EDW_Source which has 5 million records, I also added Non clustered indexes on prov_ID, SMG_ID and Incurred month for this table, but still it is taking longer time. Need help
↧
This part of query is taking long time to run, its about 40 minutes. Can anyone help wit it.
↧