我有以下两个查询,第一个按您的预期工作。第二个引发一个异常,说无效的列名 ISDELETED。但是我已经精确地添加了 if else 结构以避免该错误,在第二个查询中我做错了什么
IF COL_LENGTH('vwAs', 'IsActive') IS NOT NULL
select 1
ELSE IF COL_LENGTH('vwABCs', 'IsDeleted') IS NOT NULL
select 0
ELSE SELECT -1
和
IF COL_LENGTH('vwAs', 'IsActive') IS NOT NULL
select Count(*) [vwB] from [vwAs] WHERE ISACTIVE = 1
ELSE IF COL_LENGTH('vwABCs', 'IsDeleted') IS NOT NULL
select Count(*) [vwABCsActive] from [vwABCs] WHERE ISDELETED = 0
ELSE SELECT -1