Thursday, December 17, 2015

Example of routine in sql that if a column(s) value(s) exists and then return the key.


IF EXISTS (SELECT Coursework_ID From Coursework_Validation Where Outside_Institution_ID = @Outside_Institution_ID and Outside_CourseName=@Outside_CourseName and Outside_Subject=@Outside_Subject and Outside_CourseNum=@Outside_CourseNum)
BEGIN
SET @id= (SELECT Coursework_ID From Coursework_Validation Where Outside_Institution_ID = @Outside_Institution_ID and Outside_CourseName=@Outside_CourseName and Outside_Subject=@Outside_Subject and Outside_CourseNum=@Outside_CourseNum)
END
ELSE
BEGIN
SET @id= -9;
END
return @id

No comments:

Post a Comment