我不确定为什么以下子查询在 SQL Server 中不起作用,当我自己运行子查询时它工作得很好,但是只要我添加
Select * from ([subquery]) as table1
查询没有运行,SQL Server 返回一个错误,说我在关键字“if”附近有不正确的语法,这里存在什么语法错误,否则它怎么会正常工作?
任何指针?
select * from (
if datepart(MONTH, getdate()) >= MONTH('1/February/0000')
--after february we want the next years semesters,
begin
select top 3 sem_name from semester_dates
where datepart(year, start_date) < datepart(YEAR, getdate()) and sem_name not like 'summer%'
end
else
begin
select top 3 sem_name from semester_dates sd
where datepart(year, start_date) >= datepart(YEAR, getdate()) and sem_name not like 'summer%'
end
) table1