2010-06-30 6 views
0

voici mon code qui fonctionne grâce à Jim b:accès: instruction IIF et COUNT

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; 

retourne ceci:

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 

c'est exactement ce que je dois cependant, il y a une chose légère de. j'ai besoin qu'il compte '1.11 Autre'

Comment puis-je le faire? d'autres mots c'est la sortie j'ai besoin:

? 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 

comme vous pouvez le voir il n'y a qu'une seule occurrence de 1.11 Other et un nombre total de 19

JIM B suggère ceci:

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

mais Je ne comprends pas comment l'implémenter. aidez s'il vous plaît!

Répondre

1

Plus d'un gars de serveur sql donc je ne sais pas si vous pouvez le faire, mais vous avez essayé:

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; 
+0

merci beaucoup ce Wroked! –

1

La solution que vous avez utilisée dans l'instruction de colonne doit également être contenue dans la fonction de comptage. Parce que vous voulez compter sur les données de colonne révisées plutôt que sur les données de colonne d'origine.

+0

s'il vous plaît montrez-moi avec le code merci –

+0

vous voulez dire comme ça? http://pastebin.com/siESPmUs il est en train de retourner la même chose mais aucune erreur –

1

Peut-être quelque chose comme ça?

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; 
+0

merci beaucoup j'apprécie vraiment l'aide –