tags:

views:

23

answers:

3

here's my code that works thanks to Jim b:

SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]
HAVING ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0)
ORDER BY Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) DESC;

it returns this:

1.1 Specimen Mislabeled 159
1.3 QNS-Quantity Not Sufficient 84
1.9 QNS- Specimen Spilled in transit    72
1.6 Test Requisition Missing    17
1.11 Other  3
1.11 Other  3
1.1 Specimen Mislabeled-new ID # given  2
1.11 Other  2
1.11 Other  2
1.1 Specimen Mislabeled & 1.6 Test Requisition Missing  1
1.11 Other  1
1.11 Other  1
1.11 Other  1
1.11 Other  1
1.11 Other  1
? Nothing in comments portion of QuikLab    1
1.11 Other  1
1.11 Other  1
1.4 Tests Missed/ Wrong Test Ordered    1
1.4 Tests Missed/Wrong Test Ordered 1
1.6 Test Requisition Missing & 1.7 Specimen Lost    1
1.8 Specimen not handled/processed correctly & 1.10 Operator Error(?)   1
1.11 Other  1
1.11 Other  1

this is exactly what i need HOWEVER, there is one slight thing off. i need it to be counting '1.11 Other'

how do i do it? another words this is the output I need:

? Nothing in comments portion of QuikLab    1
1.1 Specimen Mislabeled 159
1.1 Specimen Mislabeled & 1.6 Test Requisition Missing  1
1.1 Specimen Mislabeled-new ID # given  2
1.11 Other  19
1.3 QNS-Quantity Not Sufficient 84
1.4 Tests Missed/ Wrong Test Ordered    1
1.4 Tests Missed/Wrong Test Ordered 1
1.6 Test Requisition Missing    17
1.6 Test Requisition Missing & 1.7 Specimen Lost    1
1.8 Specimen not handled/processed correctly & 1.10 Operator Error(?)   1
1.9 QNS- Specimen Spilled in transit    72

as you can see there is only one occurrence of 1.11 Other and a total count of 19

JIM B suggests this:

Use your IIF statement all the way through your group by and having clauses – Jim B

but i do not understand how to implement it. please help!

+1  A: 

The solution you used in the column statement also needs to be contained within the count function. Because you want it to count based on the revised column data rather than the original column data.

spinon
please show me with code thank u
i am a girl
do u mean like this? http://pastebin.com/siESPmUs it's actually returning the same thing but no error
i am a girl
+1  A: 

More of a sql server guy so i am not sure if you can do this but have you tried:

SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
HAVING ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0)
ORDER BY Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) DESC;
Ben Robinson
thanks very much this wroked!
i am a girl
+1  A: 

Maybe something like this?

SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
HAVING ((Count(IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])))<>0)
ORDER BY Count(IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])) DESC;
Jim B
thanks so much i really appreciate the help
i am a girl