How to generate a counter within a select (SQL server)

0

I need to make a select with a case, if the condition is true I need to use a counter that will be a new column, otherwise the counter will be displayed without any changes, but I'm not able to do it, I tried the ROW_NUMBER function but it did not work , if someone can help me I thank:

    declare @c int 
    set @c = 0
    select 
    (
         case when HR_ENTRADA > is null then
         (
             (ROW_NUMBER()over(order by HR_ENTRADA asc)+@c) 
         )
         else
         (
           @c
         )
        end
   )as FALTAS

    from TB_REGISTRO_PONTO

This query works, but if it falls into the else, this row_number counter adds tmb, and I do not want it, I just want it to add if the condition is true.

    
asked by anonymous 01.03.2018 / 17:51

1 answer

0

I do not know if I understand the question well, but is this what you want?

SELECT
    SUM(CASE WHEN {CONDIÇÃO VERDADEIRA} THEN 1 ELSE 0 END) AS FALTAS
FROM
    TB_REGISTRO_PONTO
    
01.03.2018 / 17:58