删除动态SQL数据透视中的NULLS行

时间:2018-11-06 14:35:18

标签: sql-server tsql

美好的一天。请帮助我删除Dynamic SQL Pivot中的NULLS行:

enter image description here

查询为:

SELECT *
FROM
(
SELECT  person_id,
    Name,
    activity_id,
    concat(activity collate database_default, 
           case when activity = 'maintainance' 
                then row_number() over (partition by Name,activity order by activitydate) 
                else '' 
           end  collate database_default) as activity
FROM PesonActivities    
)t
PIVOT(MAX(activity_id) FOR activity IN (
[purchased],
[installed],
[maintainance1],
[maintainance2],
[maintainance3]))p

1 个答案:

答案 0 :(得分:1)

我只想在PIVOT之后添加一个位置

...
Where concat([purchased],[installed],[maintainance1],[maintainance2],[maintainance3])<>''