Showing posts with label grouping. Show all posts
Showing posts with label grouping. Show all posts

Monday, March 19, 2012

Missing Value Grouping

Newbie SQL Question.

I need to build a results grid that reports totals or zero for an attribute

SELECT ClaimType, VendorNumber,
COUNT (ClaimNumber) AS ClaimCount
FROM ClaimHeader
GROUP BY VendorNumber, ClaimType
ORDER BY VendorNumber ASC;

THe underlying data has two claim types (UB, and HCFA). Some vendor numbers have only UB claims or only HCFA claims. I want my totals to show a zero for those vendor numbers. Example

VendorNumber ClaimType ClaimCount
234 UB 21
234 HCFA 12
235 UB 0
235 HCFA 15

My current group by doesn't give me the 3rd row in my example. How do I change my query to add those rows that have no claims as a zero. Put another way, every vendorNumber has to report a HCFA total and a UB total, even if they're zero.

Thanks.This is flat-out "brute force" to get the job done using only what you've given us... There is almost certainly a better way.SELECT v.VendorNumber, c.ClaimType, (SELECT Coalesce(Count(*), 0)
FROM ClaimHeader AS ch
WHERE ch.VendorNumber = v.VendorNumber
AND ch.ClaimType = c.ClaimType) AS ClaimCount
FROM (SELECT DISTINCT VendorNumber
FROM ClaimHeader) AS v
CROSS JOIN (SELECT DISTINCT ClaimType
FROM ClaimHeader) AS c-PatP|||Is something else I could provide to help with my question? This might b closer but i'm still missing the zeros for providers with not HCFA or UB claims.

SELECT t.PeriodID, p.ProviderName, p.AltProviderID_1,
t.FormTypeID,
ClaimCount = CASE WHEN SUM(ClaimCount) IS NULL THEN 0 ELSE SUM(ClaimCount) END

FROM dvTATClaim t
INNER JOIN dimProvider p
ON t.ProviderID = p.ProviderID|||Sure...provide the DDL of the table

CREATE TABLE myTable...

Some Sample Data

INSERT INTO myTable(
SELECT 'data' UNION ALL
SELECT 'data' UNION ALL
ect

And what the results should look like...

You could probably use a stop watch to time how long it takes after you post that for your answer...|||Are there other tables that have:
1. Every possible VendorNumber
2. Every possible ClaimType

Also, did the previous query I provided give you the results that you want?

-PatP

Friday, March 9, 2012

Missing Row in CSV Export

Hi Everyone,
I'm having an issue with a row of data missing when exporting to CSV.
The report structure is as follows:
Group 1 Header - Grouping on State (Displays the State)
Group 2 Header - Grouping on Customer ID (Displays a summary for each
customer)
Detail Row - <This Row has Been Removed>
Group 2 Footer - <This Row has Been Removed>
Group 1 Footer - Displays totals for the state
The report renders fine to PDF and will export all data to XML. When I
export to CSV, the first row is always missing. I have two reports with
similar structure and suffers from the same issue.
Any help would be greatly appreciated.
Thanks
ChadIf you add rectangle/ blank image / blank label above your report, CSV export
will work.
"Chad McKee" wrote:
> Hi Everyone,
> I'm having an issue with a row of data missing when exporting to CSV.
> The report structure is as follows:
> Group 1 Header - Grouping on State (Displays the State)
> Group 2 Header - Grouping on Customer ID (Displays a summary for each
> customer)
> Detail Row - <This Row has Been Removed>
> Group 2 Footer - <This Row has Been Removed>
> Group 1 Footer - Displays totals for the state
> The report renders fine to PDF and will export all data to XML. When I
> export to CSV, the first row is always missing. I have two reports with
> similar structure and suffers from the same issue.
> Any help would be greatly appreciated.
> Thanks
> Chad
>|||We have posted a hotfix that includes a fix for this issue at
http://www.microsoft.com/downloads/details.aspx?FamilyId=7FFE50D4-AFF8-4C1E-9609-6798190C2D58&displaylang=en.
--
Brian Welcker
Group Program Manager
Microsoft SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
"Chad McKee" <cmckee@.startech-comp.com> wrote in message
news:%2340961OeFHA.3048@.TK2MSFTNGP12.phx.gbl...
> Hi Everyone,
> I'm having an issue with a row of data missing when exporting to CSV. The
> report structure is as follows:
> Group 1 Header - Grouping on State (Displays the State)
> Group 2 Header - Grouping on Customer ID (Displays a summary for each
> customer)
> Detail Row - <This Row has Been Removed>
> Group 2 Footer - <This Row has Been Removed>
> Group 1 Footer - Displays totals for the state
> The report renders fine to PDF and will export all data to XML. When I
> export to CSV, the first row is always missing. I have two reports with
> similar structure and suffers from the same issue.
> Any help would be greatly appreciated.
> Thanks
> Chad|||> The report renders fine to PDF and will export all data to XML. When I
> export to CSV, the first row is always missing. I have two reports with
> similar structure and suffers from the same issue.
Hmm, haven't looked into the problem but maybe the CSV export is getting
confused with header rows. In case you just can't find a work-around, a
custom CSV rendering extension might be the solution. I imagine that
shouldn't be too hard to accomplish.
Christoph|||Thanks to everyone who replied. The Hotfix fixed the issue.
Thanks
Chad
Brian Welcker [MSFT] wrote:
> We have posted a hotfix that includes a fix for this issue at
> http://www.microsoft.com/downloads/details.aspx?FamilyId=7FFE50D4-AFF8-4C1E-9609-6798190C2D58&displaylang=en.
>