none
Select count com Criterio RRS feed

  • Question

  • Boa noite,

    Tenho uma situação que preciso verificar uma condição antes de contar, porem são 20 possibilidades no mesmo campo

    Ao invés de fazer 20 "IIF" alguém teria uma sugestão melhor ?

    Segue um dos IIF,s

    IIF(Qry_NotasSap_Tempo.INST Like 'MULTIFUNCAO',(SELECT COUNT(Qry_NotasSap_Tempo.LOCAL) FROM Qry_NotasSap_Tempo Where Qry_NotasSap_Tempo.LOC_INST = 'MULTIFUNCAO')) AS Qtde_Equip

    Não queria ter que fazer essa condição 20x(Uma para cada INST).

    Apesar que tentei porem quando chego no IIF 17 começa da erro(Não sei se tem limite de IFF em uma Consulta).


    Desde de Ja obrigado !

    Saturday, April 23, 2016 9:12 PM

Answers

  • Resolvi contanto na tabela de origem.

    Obrigado !

    (Select COUNT(tbl_BaseSap.Local_Instalacao) FROM tbl_BaseSap WHERE Qry_NotasSap_Tempo.LOC_INST Like tbl_BaseSap.Frota ) AS Qtde_Equip

    • Marked as answer by RJ_Silva Sunday, April 24, 2016 4:59 PM
    Sunday, April 24, 2016 4:59 PM

All replies

  • Using multiple if then (else) is poor programming. Instead you use Select (aka switch in C):

    myCase = (SQL result)

    Select Case myCase

    Case SQLCase1
    Debug.Print("myCase is 1")

    Case SQLCase2

    ....

    etc ..

    End Select


    Best regards, George


    Sunday, April 24, 2016 12:19 PM
  • Resolvi contanto na tabela de origem.

    Obrigado !

    (Select COUNT(tbl_BaseSap.Local_Instalacao) FROM tbl_BaseSap WHERE Qry_NotasSap_Tempo.LOC_INST Like tbl_BaseSap.Frota ) AS Qtde_Equip

    • Marked as answer by RJ_Silva Sunday, April 24, 2016 4:59 PM
    Sunday, April 24, 2016 4:59 PM
  • Hi RJ_Silva,

    its good to hear that you find the solution by yourself and you have also post the solution. Thank you for posting the solution so that if some one having same issue like you can also get solution by your post.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 25, 2016 4:45 AM
    Moderator