1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] SQL Server... Union all on two IF conditions

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 7, 2024 às 12:32.

  1. Stack

    Stack Membro Participativo

    I have two table valued functions which I need to do some selects... I was trying to do UNION on that selects but I can't do "union all" to my IF... It should return one row and two columns each if condition...

    This code should return:

    September | 50

    October | 33


    how can I do this?!

    this was my code:

    IF (select TotalTreinos from dbo.tbl_CALCULA_TREINOS_MES('20160901','20160930',2,5)) = (SELECT Presencas FROM DBO.tbl_CALCULA_PRESENCAS('Setembro',9,2))
    SELECT 'Setembro' as Mes, 100 AS PercentPresencas
    else
    select 'Setembro' as Mes, (((SELECT Presencas FROM DBO.tbl_CALCULA_PRESENCAS('Setembro',9,2)) * 100) / (select TotalTreinos from dbo.tbl_CALCULA_TREINOS_MES('20160901','20160930',2,5))) as PercentPresencas

    union all

    IF (select TotalTreinos from dbo.tbl_CALCULA_TREINOS_MES('20161001','20161031',2,5)) = (SELECT Presencas FROM DBO.tbl_CALCULA_PRESENCAS('Outubro',10,2))
    SELECT 'Outubro' as Mes, 100 AS PercentPresencas
    else
    select 'Outubro' as Mes,(((SELECT Presencas FROM DBO.tbl_CALCULA_PRESENCAS('Outubro',10,2)) * 100) / (select TotalTreinos from dbo.tbl_CALCULA_TREINOS_MES('20161001','20161031',2,5))) as PercentPresencas

    Continue reading...

Compartilhe esta Página