is there’s a better way to get a daily sequence # from this sql proc
DECLARE @id int
UPDATE daily_identity
SET id = id + 1, @id = id + 1
WHERE day = CONVERT(VARCHAR(8), GETDATE(), 112)
IF @@ROWCOUNT = 0
INSERT INTO daily_identity values ( CONVERT(VARCHAR(8), GETDATE(), 112), 1 )
SELECT @id = 1
END IF
SELECT @id AS ‘id’
Looks like an accident waiting to happen without a very restrictive transaction wrapped around it.
EDIT: Emphasized that the
Row_Number()calculation depends on numbering all of the rows.How about always doing an
INSERTand using the result to generate a displayed daily Id? Do you see anything useful in this:Note that terrible things will happen if rows are deleted. The daily Ids will recalculate in thrilling ways.