Det, du vil gøre, kaldes pivot
Prøv at bruge denne kode
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
Du kan tjekke sql-dokumentation på PIVOT og UNPIVOT på PIVOT, UNPIVOT SQL , Hvis du vil have noget mere dynamisk til dine transdate-felter, kan du tjekke Dynamisk pivot