WHERE TableName = @TableName AND FieldName = @FieldName
IF @@ROWCOUNT = 0
BEGIN
BEGIN TRY
-- This expects unique or PK index defined on the dbo.tbl_ID_Sequence table
INSERT INTO dbo.tbl_ID_Sequence (NextIDValue, TableName, FieldName)
VALUES (1, @TableName, @FieldName)
SET @NextID = 1
END TRY
BEGIN CATCH
-- The above INSERT may fail when the row exists already, so use just the UPDATE
UPDATE dbo.tbl_ID_Sequence SET @NextID = NextIDValue = NextIDValue+1
WHERE TableName = @TableName AND FieldName = @FieldName
END CATCH
END
END
SELECT @NextID
```
No Schema set on the custom query. I've tried with and without. Need to figure out how to assign something to that "". But I did something simliar to this before with a storedprocedure and there was just a way to code it, @patrick helped me. I just can't remember where that code was to look at it again.