Problem with running total

  • Here is my code. This code calculates a YTD total for CPT codes (CPT) by month. If a particular CPT code is missing from the data in a particular month, the YTD total is incorrect. How can I fix this?

    select PostPeriod, NPI, provider, location, location_mapping, location_category, category, CPT, modifier, multiplier, wRVU10,

    MTDCharges, MTDUnits, AdjwRVU10, MTDNetwRVU10,

    (select sum(isnull(b.MTDUnits,0))

    from #T2 b

    where b.PostPeriod<=a.PostPeriod

    and b.NPI=a.NPI

    and b.location=a.location

    and b.category=a.category

    and b.CPT=a.CPT

    and b.modifier=a.modifier) as YTDUnits

    --into #T3

    from #T2 a

    where PostPeriod<='11103'

    and category='ADMIN/INJ'

    -- and NPI='1144201005'

    -- and CPT='090471'

    group by PostPeriod, NPI, provider, location, location_category, location_mapping, category, CPT, modifier, multiplier, wRVU10,

    MTDCharges, MTDUnits, AdjwRVU10, MTDNetwRVU10

  • Straight SQL is not going to show you want isn't in the database, but I'm confused on how that makes the YTD figures incorrect. Is it that they are just not showing zeros? You are not doing any JOINs so you should be getting a record for everything in #T2.

    --------------------------------------------------------------------------
    When you realize you've dug yourself into a hole....Step 1...stop digging.

  • For example ........ if in January there is cpt code 93762 with 10 units, February there are 5 units, in March there are no units, so there is no record for CPT code 93762. The MTD value is zero, but the YTD should be 15. But because there is no record for March, it doesn't show up in the query.

  • Not sure if this helps. The last two fields are MTD and YTD

    110101679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a13.0013.00

    110101679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374n/a5.005.00

    110111679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a16.0029.00

    110111679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374n/a5.0010.00

    110121679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a18.0047.00

    110121679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374n/a4.0014.00

    111011679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a17.0064.00

    111011679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096372n/a7.007.00

    111011679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374n/a5.0019.00

    111021679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a25.0089.00

    111021679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096372n/a2.009.00

    111021679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374n/a1.0020.00

    111031679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096365n/a25.00114.00

    111031679552582KELLEY-HEDGEPETH M.D.,ALYSONDOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096372n/a0.009.00

  • You could create a table that is a place holder for the months (essentially 12 records). Then do a left join from that table to your data (on month or PostPeriod) and then in the case where you didn't have a match you'd have to know to display a zero for the null, but the YTD number should come through since it is a subquery.

    --------------------------------------------------------------------------
    When you realize you've dug yourself into a hole....Step 1...stop digging.

  • To be a little more clear, I'm trying to get MTD and YTD totals for the category, ADM/INJ. If you do the math "off line" it doesn't add up correctly.

  • NineIron,

    Can you setup a sample data set with schema and the like that's consumable? We can most likely help you but you'll need to give us a starting point we can work from that's not going to be vague recommendations on the approach. If you take a look at the first link in my signature it'll show you what the majority of us look for to assist in coding problems like this. You have to remember we're volunteers. The more you can give us to make it easier, the more likely we are to come and help out. 🙂

    In general, what you're going to need is placeholders for the missing data. This is usually dealt with via either derived calendar tables or something similar. I personally usually just use a Tally Table and derive my calendars on the fly, but everyone has their own preference.

    There are a few approaches but a consumable data set and allowing that to indicate the problem directly is always more helpful.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • I've attached an ACCESS db with some data. The post periods run from 11010 (October, 2011) thru 11106 (June, 2011). This data is for one provider but, many locations, categories, CPTs. I need a way to get the YTD Charges and YTD Units.

    select a.S_PostPd, a.S_ProvNPI, a.S_Location, a.location_mapping, a.location_category, a.category, a.S_CPT, a.S_modifier, sum(S_Charge_Amt) as MTDCharges,

    sum(a.S_Units) as MTDUnits,

    (select sum(isnull(b.MTDCharges,0))

    from SampleData b

    where b.S_PostPd<=a.S_PostPd

    and b.S_ProvNPI=a.S_ProvNPI

    and b.location=a.location

    and b.category=a.category

    and b.S_CPT=a.S_CPT

    and b.S_modifier=a.S_modifier),

    (select sum(isnull(b.MTDUnits,0))

    from SampleData b

    where b.S_PostPd<=a.S_PostPd

    and b.S_ProvNPI=a.S_ProvNPI

    and b.location=a.location

    and b.category=a.category

    and b.S_CPT=a.S_CPT

    and b.S_modifier=a.S_modifier)

    from SampleData a

    where S_PostPd<='11106'

    group by S_PostPd, S_ProvNPI, S_Location, location_mapping, location_category, category, S_CPT, S_modifier

  • NineIron (12/12/2011)


    I've attached an ACCESS db with some data. The post periods run from 11010 (October, 2011) thru 11106 (June, 2011). This data is for one provider but, many locations, categories, CPTs. I need a way to get the YTD Charges and YTD Units.

    My apologies, but I was apparently unclear. What I would prefer to see is runnable scripts, not a zip file containing something that can auto-run macros hiding in a zip file from someone relatively new to the boards. I'm paranoid. I will attempt to help without reviewing that file.

    Is this code intended to be run in MS Access or is that just the repository you used? Your code uses T-SQL syntax for the comments so I'm assuming this will be in SQL Server.

    Let's look at the logic of the algorithm before approaching heavy code mechanics. Assuming we have this data:

    CREATE TABLE #tmp (ForMonth DATETIME NOT NULL, AmountToUse INT NOT NULL)

    INSERT INTO #tmp SELECT * FROM (SELECT '20100101' AS ForMonth, 300 AS AmountToUse UNION ALL SELECT '20100201', 400 UNION ALL SELECT '20100401', 600 UNION ALL SELECT '20100501', 700) AS drv

    And we want to pull from 01/01/2010 through 06/01/2010, we have two gaps in the month. A direct average of this:

    SELECT AVG( AmountToUse) AS AvgAmt FROM #tmp

    equates to 500. This is inaccurate, as we're missing 0's for two months. So, what you need is a way to fake including the following data in the table:

    INSERT INTO #tmp SELECT * FROM (SELECT '20100301' AS ForMonth, 0 AS AmountToUse UNION ALL SELECT '20100601', 0) AS drv

    What you're going to need to do then is find a way to fake these rows. There are three typical approaches to this.

    1) Include the data in a local temp table and then use a cursor or loop to locate missing rows and include them in the #tmp. This is arduous to the optimizer.

    2) Create your own averaging mechanics. For example, use SUM(AmounToUse) / DATEDIFF( mm, @startDate, @EndDate). Depending on intent this can work.

    3) Use a Tally table to 'fake' your rows based on needs. Check out the link in my signature if you're unfamiliar with this mechanic and some of the uses you can use it for.

    EDIT: I should add, you'll notice I used averages as my example in this. That's because the only time 'missing data' should matter is when division somehow gets involved and your counts are off. SUM will make no difference in this scenario, so missing rows aren't the direct concern unless there's other calculations we're not seeing. This was part of why I wanted to directly see sample data, your code applying to it, and we could see the exact issue that you're having. Without that... this is nearly impossible to troubleshoot.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Jeff,

    Pardon my ignorance. I should have read your post regarding forum etiquette first.

    I hope I did this correctly.........here is three months of data for one provider. From here I need YTD charges and units. I don't have an identity column in the data.

    I studied your Tally Table post but, I couldn't apply it to this problem. I think there are too many fields to get my mind around.

    --===== If the test table already exists, drop it

    IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL

    DROP TABLE #mytable

    --===== Create the test table with

    CREATE TABLE #mytable

    (

    PostPeriod varchar(50),

    NPI varchar(50),

    location varchar(50),

    location_mapping varchar(50),

    location_category varchar(50),

    category varchar(50),

    CPT varchar(8),

    modifier nvarchar(50),

    Charges decimal(10,2),

    Units decimal(10,2)

    )

    SELECT 'SELECT '

    + QUOTENAME(S_PostPd,'''')+','

    + QUOTENAME(S_ProvNPI,'''')+','

    + QUOTENAME(S_Location,'''')+','

    + QUOTENAME(location_mapping,'''')

    + QUOTENAME(location_category,'''')

    + QUOTENAME(category,'''')

    + QUOTENAME(S_CPT,'''')

    + QUOTENAME(S_Modifier,'''')

    + QUOTENAME(sum(S_Charge_Amt),'''')

    + QUOTENAME(sum(S_Units),'''')

    + ' UNION ALL'

    FROM formatIDX_Service a

    INNER JOIN U_ref_Location b ON

    a.S_Location=b.location

    INNER JOIN U_Ref_CategoryMapping c ON

    a.S_CPT=c.CPT

    WHERE S_PostPd BETWEEN '11101' AND '11103'

    AND S_CPT!=''

    AND S_ProvNPI!=''

    AND S_ProvNPI='1679552582'

    AND charindex('(',S_Provider,1)=0

    group by S_PostPd, S_ProvNPI, S_Location, location_mapping, location_category, category, S_CPT, S_Modifier

    --===== Insert the test data into the test table

    INSERT INTO #mytable (PostPeriod, NPI, location, location_mapping, location_category, category, CPT, modifier, MTDCharges, MTDUnits)

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''ADMIN/INJ''096365'' ''2145''13' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''ADMIN/INJ''096365''59''660''4' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306'' ''12100''22' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''26''1210''11' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''TC''1760''4' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224'' ''2480''8' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224''QD''1550''5' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452'' ''9420''12' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452''26''750''6' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452''TC''500''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC OTHER''093000'' ''1265''23' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093280'' ''460''4' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093282'' ''140''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093283'' ''340''2' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093284'' ''200''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093289''26''80''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093289''TC''115''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093293'' ''120''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC STRESS''093015'' ''7830''27' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''COUNSELING''099406'' ''175''7' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096372'' ''315''7' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096374'' ''625''5' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''A9500'' ''2035''11' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J0280'' ''45''9' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J1245'' ''1050''21' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J2785'' ''1300''20' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J7050'' ''45''9' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1000F'' ''0''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1034F'' ''0''2' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''G8447'' ''0''26' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''006004'' ''0''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099051'' ''40''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213'' ''4680''36' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213''25''780''6' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099214'' ''5265''27' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099214''25''390''2' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''RAD-GL CT SCAN''076376''26''50''1' UNION ALL

    SELECT '11101','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''RAD-GL CT SCAN''076376''TC''200''1' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''3960''36' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26/52''110''1' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC NUCLEAR''078452''26''250''2' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''2115''47' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CONSULTATIONS''099254'' ''4760''14' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099222''AF''6500''25' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099223''AF''380''1' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099231'' ''160''2' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099232'' ''3780''27' UNION ALL

    SELECT '11101','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''SKILLED NURSING''099309'' ''-160''-1' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC ECHOS''093306'' ''550''1' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''1870''17' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC NUCLEAR''078452''26''125''1' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''900''20' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC STRESS''093016'' ''75''1' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC STRESS''093018'' ''155''1' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CONSULTATIONS''099244'' ''2280''6' UNION ALL

    SELECT '11101','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''OFFICE VISIT''099204''AF''600''2' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''ADMIN/INJ''096365'' ''4125''25' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306'' ''15950''29' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''26''1320''12' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''TC''440''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224'' ''3410''11' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224''QD''620''2' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452'' ''16485''21' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452''26''500''4' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452''TC''0''0' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC OTHER''093000'' ''1485''27' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093280'' ''575''5' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093282'' ''140''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093283''26''170''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093283''TC''170''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093284'' ''200''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093293'' ''240''2' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093293''26''120''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093293''TC''120''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093296'' ''80''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC STRESS''093015'' ''10440''36' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CONSULTATIONS''099244'' ''0''0' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''COUNSELING''099406'' ''50''2' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096372'' ''90''2' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096374'' ''125''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''A9500'' ''3700''20' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J0280'' ''60''12' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J1245'' ''2250''45' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J2785'' ''1040''16' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J7050'' ''60''12' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1000F'' ''0''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1034F'' ''0''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''G8447'' ''0''26' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099204''AF''1500''5' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099211'' ''160''4' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213'' ''6760''52' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213''25''390''3' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099214'' ''5265''27' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099215'' ''265''1' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''RAD-GL CT SCAN''076376'' ''750''3' UNION ALL

    SELECT '11102','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''TEST''069210'' ''95''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''5610''51' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093312''26''215''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''31725''705' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC OTHER''093010''77''225''5' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC OTHER''093010''GV''45''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC STRESS''093016'' ''375''5' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC STRESS''093018'' ''775''5' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CONSULTATIONS''099254'' ''340''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099222'' ''260''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099222''AF''3900''15' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099231'' ''80''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099232'' ''140''1' UNION ALL

    SELECT '11102','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099233'' ''-200''-1' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''2090''19' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC HOLTERS''093227'' ''210''2' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC HOLTERS''093227''QT''210''2' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''4770''106' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC STRESS''093016'' ''225''3' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC STRESS''093018'' ''465''3' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CONSULTATIONS''099244'' ''1140''3' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''PHY-HOSPITAL''099219''AF''200''1' UNION ALL

    SELECT '11102','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''PHY-HOSPITAL''099222''AF''260''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''ADMIN/INJ''096365'' ''3795''23' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''ADMIN/INJ''096365''59''330''2' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306'' ''18700''34' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''26''1980''18' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC ECHOS''093306''TC''1760''4' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224'' ''3720''12' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC HOLTERS''093224''QD''930''3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452'' ''15700''20' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC NUCLEAR''078452''26''625''5' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC OTHER''093000'' ''2035''37' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093279'' ''110''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093280'' ''345''3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093280''26''25''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093280''TC''90''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC PACERS''093283'' ''340''2' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CARDIAC STRESS''093015'' ''11600''40' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''CONSULTATIONS''099244'' ''760''2' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''COUNSELING''099406'' ''175''7' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''COUNSELING''099407'' ''100''2' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096372'' ''-135''-3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''096372''59''135''3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''A9500'' ''3885''21' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J0280'' ''40''8' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J1245'' ''775''20' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J2785'' ''1040''16' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''DRUG/INJECTABLE''J7050'' ''40''8' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1000F'' ''0''3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''1034F'' ''0''3' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''MISCELLANEOUS''G8447'' ''0''41' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099024'' ''0''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099204'' ''300''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099204''25''300''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099204''25/AF''300''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099204''AF''2100''7' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099211'' ''40''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213'' ''6630''51' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099213''25''910''7' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099214'' ''6240''32' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099215''AF''265''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''OFFICE VISIT''099215''AF/25''265''1' UNION ALL

    SELECT '11103','1679552582','DOCTORS OFFICE-LIBERTY STREET','DOCTORS OFFICE''NON LAB''RAD-GL CT SCAN''076376'' ''500''2' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093306'' ''550''1' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''4950''45' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC NUCLEAR''078452''26''750''6' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''2070''46' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC STRESS''093016''53''75''1' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CARDIAC STRESS''093018'' ''155''1' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''CONSULTATIONS''099254'' ''4420''13' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099222'' ''1040''4' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099222''AF''7280''28' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099231'' ''880''11' UNION ALL

    SELECT '11103','1679552582','INPATIENT-BROCKTON HOSPITAL','INPATIENT HOSPITAL''NON LAB''PHY-HOSPITAL''099232'' ''2240''16' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC ECHOS''093306''26''2860''26' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC ECHOS''093312''26''215''1' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC HOLTERS''093227'' ''210''2' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC NUCLEAR''078452''26''375''3' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''CARDIAC OTHER''093010'' ''540''12' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''OFFICE VISIT''099204'' ''600''2' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''OFFICE VISIT''099204''AF''900''3' UNION ALL

    SELECT '11103','1679552582','OUTPATIENT-BROCKTON HOSPITAL','OP HOSPITAL''NON LAB''PHY-HOSPITAL''099219'' ''200''1'

  • Confused :crazy:

    Scrapped post, answer not right :blush:

    Far away is close at hand in the images of elsewhere.
    Anon.

  • OK maybe this then

    ;WITH cte (Period) AS (

    SELECT '11010' UNION ALL

    SELECT '11011' UNION ALL

    SELECT '11012' UNION ALL

    SELECT '11101' UNION ALL

    SELECT '11002' UNION ALL

    SELECT '11003' UNION ALL

    SELECT '11004' UNION ALL

    SELECT '11005' UNION ALL

    SELECT '11006'

    )

    SELECTp.Period, a.S_ProvNPI, a.S_Location, a.location_mapping, a.location_category, a.category, a.S_CPT, a.S_modifier,

    SUM(CASE WHEN a.S_PostPd=p.Period THEN a.S_Charge_Amt ELSE 0.00 END) AS [MTDCharges],

    SUM(CASE WHEN a.S_PostPd=p.Period THEN a.S_Units ELSE 0.00 END) AS [MTDUnits],

    SUM(CASE WHEN a.S_PostPd<=p.Period THEN a.S_Charge_Amt ELSE 0.00 END) AS [YTDCharges],

    SUM(CASE WHEN a.S_PostPd<=p.Period THEN a.S_Units ELSE 0.00 END) AS [YTDUnits],

    FROMSampleData a

    CROSS JOIN cte p

    WHEREa.S_PostPd>='11010' AND a.S_PostPd<='11106'

    GROUPBY p.Period, S_ProvNPI, S_Location, location_mapping, location_category, category, S_CPT, S_modifier

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Nope. There is a record in PostPeriod 11102 with the code 096374.

    This code is not in 11103 so, it is not calculating the YTD correctly.

    S_PostPdS_ProvNPIS_Locationlocation_mappinglocation_categorycategoryS_CPTS_ModifierS_Charge_AmtS_Units

    111021679552582DOCTORS OFFICE-LIBERTY STREETDOCTORS OFFICENON LABADMIN/INJ096374 1251

  • Also, the MTD and YTD should be the same value for 11010.

    Please use the code in the previous post for the data. I made a mistake by not following the forum etiquette earlier and would like to get back on track the right way.

  • 1) your last set of sample data seems to be missing the last 5 or 6 commas between the 'fields' of data.

    2) you need to construct a SIMPLE set of sample data that shows both CORRECT output and INCORRECT output and state clearly what output you get and what output you expect based on that sample data.

    3) you also mislabled the last 2 columns in your INSERT

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply