Wat je wilt doen heet pivot
Probeer deze code te gebruiken
SELECT employeeid
,case when [2018-10-1] > 0 then '1' else '' end as [2018-10-1]
,case when [2018-10-2] > 0 then '1' else '' end as [2018-10-2]
,case when [2018-10-3] > 0 then '1' else '' end as [2018-10-3]
FROM(
SELECT employeeid
, TranDate
, 1 as num
FROM History
WHERE (CAST(trandate as DATE) = '2018-10-1'
or CAST(trandate as DATE) = '2018-10-2'
or CAST(trandate as DATE) = '2018-10-3' )
)
PIVOT(
COUNT(num)
FOR TranDate IN ([2018-10-1],[2018-10-2],[2018-10-3])
) as pvt
U kunt de sql-documentatie over PIVOT en UNPIVOT raadplegen op PIVOT, UNPIVOT SQL , Ook als u iets dynamischer wilt voor uw transdate-velden, kunt u controleren Dynamische draaiing