0
I need to make a select with a case, if the condition is true use a counter that will be a new column, otherwise the counter will be displayed without any change, but I’m not succeeding, I tried with the ROW_NUMBER function but it did not work, if anyone can help me I appreciate:
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 you fall into Else, this row_number tmb counter adds, and I don’t want that, I just want it to add if the condition is true.
Can put an example of the expected result?
– EmanuelF
It is a point control, the query is only to check if the employee has mark in the input time, regardless of what time he hit the input, IE, if in this column have no value (NULL) will be a foul, and the counter adds 1.
– Rodrigo Lima dos Santos
You could try changing your logic to:
case when HR_ENTRADA is null then
or need to have Else. It has better ways to count.– EmanuelF