使用下面的sql语句从表字段中获取最后一个填充列但不能使其工作。
select
iif(isnull(AppBy11,true),
iif(isnull(AppBy10,true),
iif(isnull(AppBy9,true),
iif(isnull(AppBy8,true),
iif(isnull(AppBy7,true),
iif(isnull(AppBy6,true),
iif(isnull(AppBy5,true),
iif(isnull(AppBy4,true),
iif(isnull(AppBy3,true),
iif(isnull(AppBy2,true), "", AppBy2), AppBy3), AppBy4), AppBy5), AppBy6), AppBy7), AppBy8), AppBy9, AppBy10), AppBy11) as Result
from entry
有没有其他方法可以达到预期效果的闪电速度?我将为600万个数据运行此查询。
答案 0 :(得分:4)
利用COALESCE (Transact-SQL)。它将在列表中返回第一个NOT Null列值。
SELECT COALESCE(AppBy11, AppBy10,AppBy9,AppBy8,AppBy7,AppBy6,AppBy5,AppBy4,AppBy3,AppBy2,AppBy1) as Result
FROM entry