Created
February 25, 2013 04:34
-
-
Save lukencode/5027766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE spNextStudySequence | |
@StudyID int | |
AS | |
DECLARE @temp table | |
( | |
ID bigint | |
); | |
UPDATE tStudy_Sequences | |
SET Sequence = Sequence + 1 | |
OUTPUT INSERTED.Sequence into @temp | |
WHERE StudyID = @StudyID; | |
IF NOT EXISTS (SELECT 1 FROM @temp) | |
BEGIN | |
INSERT INTO tStudy_Sequences(StudyID, Sequence) VALUES(@StudyID, 1) | |
INSERT INTO @temp VALUES(1) | |
END | |
SELECT TOP(1) * FROM @temp | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment