Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318470
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:42:35+00:00 2026-05-17T22:42:35+00:00

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER Procedure [dbo].[spGetQualityReport] ( @providerKey INT

  • 0
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[spGetQualityReport]
 (
  @providerKey INT          
 )

AS


-- declare @providerKey INT          

-- set @providerKey = 1;

--Get Database providerId first
DECLARE @realProvId INT;
SET @realProvId = (SELECT TOP(1) providerId from providerKeyTranslation where keyValue LIKE @providerKey)-- Nine to be replaced by datasource

DECLARE @ProviderName varchar(500);
SET @ProviderName = (SELECT name FROM provider WHERE id = @realProvId)

DECLARE @cmsId varchar(50);
SET @cmsId = (select top(1) KeyValue from ProviderKeyTranslation pkt where @realProvId = pkt.ProviderId)

DECLARE @ProviderType varchar(200);
SET @ProviderType = (select name from providertype where id = (select providertypeid from provider where id =@realProvId))

DECLARE @stateValue INT;
SET @stateValue = (SELECT TOP(1) KeyValue from providerKeyTranslation where ProviderId = @realProvId)

(
SELECT DISTINCT
(select d.Name + ' - ' + d.Description from DataSource d where pcmv.DataSourceId = d.Id) as [Source],
m.Id as [Measure Key],
m.Name AS MeasureName,
cmm.Ordering as [Measure Sort Order], --(SELECT DISTINCT ordering FROM dbo.fnGetProviderMeasureSortOrder(@realProvId,pcmv.CategoryId,pcmv.MeasureId)), --(select Ordering from Category_Measure_Map cmm where cmm.MeasureId = pcmv.MeasureId and cmm.CategoryId = pcmv.CategoryId) as [Measure Sort Order],
(select Name from DataSource_Locale ds where pcmv.ProviderId = @realProvId and pcmv.DataSourceId = ds.Id) as [Dates of Measures],
@stateValue AS [State Value],
m.UnitTypeId,
@realProvId AS [Provider Id], 
@ProviderName AS [Provider Name],
@ProviderType as [Provider Type],
@cmsId as [CMS ID],
Value AS [Value],
pcmv.ConditionId,
pcmv.Denominator,  
(select Name from Condition c where c.Id = pcmv.ConditionId) as [Condition],
(select TOP(1)rg.Name from Report r, ReportGrouping rg where r.ConditionId = pcmv.ConditionId AND r.ReportGroupingId = rg.Id) as [Condition Type],
(select Ordering from Report r where r.ConditionId = pcmv.ConditionId) as [Condition Sort Order],
case when (r.rating = 1) then '$'
when (r.rating = 2) then '$$'
when (r.rating = 3) then '$$$'
when (r.rating = 4) then '$$$$' end
AS Rating,
sig.Name AS Significance, 
f.Name AS FootNote,
pcmv.Deaths,
pcmv.ObsRate,
pcmv.ExpRate,
pcmv.LowCI,
pcmv.UpperCI
FROM Measure m
RIGHT JOIN
(
providerConditionMeasureValue pcmv   
INNER JOIN Provider p on p.Id = pcmv.ProviderId and p.Id = @realProvId
INNER JOIN dbo.Category_Measure_Map cmm ON cmm.MeasureId = pcmv.MeasureId AND cmm.CategoryId = pcmv.CategoryId AND pcmv.ProviderId = @realProvId
LEFT JOIN Rating r 
 on pcmv.Rating = r.Id
LEFT JOIN Footnote f 
 on pcmv.FootnoteId = f.Id 
LEFT JOIN Significance sig 
 on pcmv.SignificanceId = sig.Id  

) ON m.Id = pcmv.MeasureId
--CROSS JOIN dbo.DataSource AS d
where m.MeasureTypeId = 1  /*Quality Measure Type */
--Group BY m.Id, m.Name, m.UnitTypeId, pcmv.MeasureId, pcmv.DataSourceId, pcmv.CategoryId, pcmv.providerId, p.Name, Value,pcmv.ConditionId,r.rating, sig.Name, f.Name, pcmv.Deaths, pcmv.ObsRate, pcmv.ExpRate, pcmv.LowCI, pcmv.UpperCI, pcmv.Denominator
)
UNION
(
SELECT 
(select d.Name + ' - ' + d.Description from DataSource d where pmv.DataSourceId = d.Id) as [Source],
m.Id as [Measure Key],
m.Name AS MeasureName,
cmm.Ordering as [Measure Sort Order],--(select Ordering from Category_Measure_Map cmm where cmm.MeasureId = pmv.MeasureId and cmm.CategoryId = pmv.CategoryId) as [Measure Sort Order],
(select Name from DataSource_Locale ds where pmv.ProviderId = @realProvId and pmv.DataSourceId = ds.Id) as [Dates of Measures],
@stateValue AS [State Value],
m.UnitTypeId,
@realProvId AS [Provider Id], 
@ProviderName AS [Provider Name],
@ProviderType as [Provider Type],
@cmsId as [CMS ID],
Value AS [Value],  
null,
pmv.Denominator,
NULL,
null,
NULL,
case when (r.rating = 1) then '$'
when (r.rating = 2) then '$$'
when (r.rating = 3) then '$$$'
when (r.rating = 4) then '$$$$' end
AS Rating,
sig.Name AS Significance, 
f.Name AS FootNote,
pmv.Deaths,
pmv.ObsRate,
pmv.ExpRate,
pmv.LowCI,
pmv.UpperCI

FROM Measure m
RIGHT JOIN
(
providerMeasureValue pmv   
INNER JOIN Provider p on p.Id = pmv.ProviderId and p.Id = @realProvId
INNER JOIN dbo.Category_Measure_Map cmm ON cmm.MeasureId = pmv.MeasureId AND cmm.CategoryId = pmv.CategoryId AND pmv.ProviderId = @realProvId
LEFT JOIN Rating r 
 on pmv.Rating = r.Id
LEFT JOIN Footnote f 
 on pmv.FootnoteId = f.Id 
LEFT JOIN Significance sig 
 on pmv.SignificanceId = sig.Id  

) ON m.Id = pmv.MeasureId
--CROSS JOIN dbo.DataSource AS d
where m.MeasureTypeId = 1/*Quality Measure Type */
--Group BY m.Id, m.Name, pmv.MeasureId, pmv.DataSourceId, pmv.CategoryId, m.UnitTypeId, pmv.providerId, p.Name, Value,r.rating, sig.Name, f.Name,  pmv.Deaths, pmv.ObsRate, pmv.ExpRate,pmv.LowCI,pmv.UpperCI, pmv.Denominator
)

Working on a stored procedure and it keeps returning the multiple measure sort order even though there is only one mapping in the category measure table. Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:42:35+00:00Added an answer on May 17, 2026 at 10:42 pm

    You need to break it down and build it back up carefully – one of your joins is creating an inadvertent many-to-one join – perhaps you’ve left out a condition in the join or one of your assumptions is not holding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[FlowClientGetCatWeb] (@ID_Izmerit Integer, @ID_User Integer,
I am using following storedprocedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO Alter PROCEDURE
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create PROCEDURE [dbo].[SD_Sproc_Insurance_Insert] -- Add the
i have this stored procedure to look up uk postcodes.. SET ANSI_NULLS ON GO
I have to following sproc: USE [CW] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER
USE [PreMfg] GO /****** Object: StoredProcedure [dbo].[procAddOrderItem] Script Date: 08/11/2011 10:28:21 ******/ SET ANSI_NULLS
i am using a stored procedure to run some queries in my database. The
How would i will stop looping if the value is already existing? set ANSI_NULLS
What would be a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible) which
:set ic ignores the case. How do you unset this?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.