maximum value + 1 with case in sqlserver

0

How can I make a sql query where I select the maximum value of the folio column plus one, taking into account that the table may be empty the first time it is used, I have the following query but I think it is missing more.

the query to get the maximum value + one is:

SELECT MAX(FOLIO)+1 AS FOLIOSIGUIENTE FROM LOTE_ENVIO 

and the query I have is with a case so that when the value is 0 then I change it to 1

SELECT 
CASE MAX(FOLIO)
 WHEN '0' THEN '1' 
 ELSE '1' 
END 
FROM LOTE_ENVIO

can be done in a single instruction?

    
asked by Ivxn 02.08.2016 в 19:47
source

1 answer

2

You could evaluate

SELECT ISNULL(MAX(FOLIO), 0) + 1 AS FOLIOSIGUIENTE FROM LOTE_ENVIO 
    
answered by 02.08.2016 / 19:49
source