不是一个SQL人。有一个顾问写的以下代码。
首先,它确保只选择了一所小学 – 然后,在BEGIN之后,如果变量@Term等于3,我们要在IF语句下执行这些操作。这里的问题。当@Term不是= 3时,我们仍然希望下拉并执行SECOND INSERT INTO @Classes部分。 FYI – 当运行时Term为= 3,但它不是同时执行INSERT – 如果在“IF @Term = 3”部分的末尾有一个END IF,而不是一个简单的END?
IF @SchoolCategoryCode = 'Elem'
--- We now have determined we are processing an elementary school...
BEGIN
---- Only do the following if the variable @Term equals a 3 - if it does not, skip just this first part
IF @Term = 3
BEGIN
INSERT INTO @Classes
SELECT
XXXXXX
FROM XXXX blah blah blah
END
---- **always** "fall thru" to here, no matter what @Term is equal to - always do the following INSERT for all elementary schools
INSERT INTO @Classes
SELECT
XXXXXXXX
FROM XXXXXX (more code)
END