1

아래의 SQL 문을 사용하여 테이블 필드에서 마지막으로 채워진 열을 가져 오지만 작동하지 않게합니다.결과로 마지막으로 채워진 열 값을 검색하는 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 

enter image description here

예상 된 결과를 도착하는 번개 속도에서 작동 다른 방법이 있습니까? 6 백만 데이터에 대해이 쿼리를 실행할 것입니다.

답변

4

COALESCE (Transact-SQL)을 사용하십시오. 목록에서 첫 x 째 NOT NULL C 럼 값을 리턴합니다.

SELECT COALESCE(AppBy11, AppBy10,AppBy9,AppBy8,AppBy7,AppBy6,AppBy5,AppBy4,AppBy3,AppBy2,AppBy1) as Result 
FROM entry 
+1

와우 너무 간단하고 효율적입니다. 고마워요 :) – Sixthsense

+0

도와 드리겠습니다 :) –