SELECT b.*, (CASE WHEN EXISTS
(SELECT 1 FROM QZJ_UseRegDriverInUsing as a
WHERE b.ItemId = a.UseRegDriverID AND
isUseRegCancel = 0 AND
isApply = 1) THEN '锁定' ELSE '未锁定' END) AS isUsing
FROM QZJ_UseRegDriver b
problem:
Check this exam, written exam bumban if someone reaches 80 points or more, the person put 2 points. Otherwise, each person allowed to put 5 points.
analysis:
Does anyone have the written test results reach 80 points or more, can be used EXISTS test. SQL statements as in Example 8 FIG.
Example 8
/ * - using EXISTS subqueries, as appropriate, plus - * /
IF EXISTS (SELECT * FROM stuMarks WHERE writtenExam>80)
BEGIN
print ' This class points higher than it was written exam, each extra points, extra points after the score: '
UPDATE stuMarks SET writtenExam=writtenExam+2
SELECT * FROM stumarks
END
ELSE
BEGIN
print ' bumban points no higher than the written test results, each can be a plus, the plus score: '
UPDATE stuMarks SET writtenExam=writtenExam+5
SELECT * FROM stumarks
END
GO
Reproduced in: https: //www.cnblogs.com/tutuyforever/p/3198264.html