Hi,
I created a SP ages ago that gives me these columns based on a @Param executed which is a company name, i.e. XYZ Ltd:
Visitor Type
Date
Weekday
Visitor Name
Location
Company
Time In
Time Out
Duration (hh:mm)
Here is the SP:
SELECT
format(cast([Visitor].[ArrivalDateTime] as date),'dd MMM yyyy') AS 'Date',
FORMAT([Visitor].[ArrivalDateTime],'dddd') AS 'Weekday',
[Location].[VisitorTypeName] AS 'Visitor Type',
[Visitor].[VisitorName] AS 'Visitor Name',
[Location].[Name] AS 'Location',
[Client].[Name] AS 'Company',
--[Visitor].[ArrivalDateTime] AS ORDER_BY_TC0,
Min(CONVERT(VARCHAR(30), ([Visitor].[ArrivalDateTime]), 108) ) AS 'Time In',
Max(CONVERT(VARCHAR(30), ([Visitor].[DepartureDateTime]), 108) ) AS 'Time Out',
CONVERT(char(5),DATEADD(second, (DATEDIFF(Second, Min(CONVERT(VARCHAR(30), ([Visitor].[ArrivalDateTime]), 108) ), Max(CONVERT(VARCHAR(30), ([Visitor].[DepartureDateTime]), 108) ))),'19000101'), 108) AS 'Duration (hh:mm)'
--DATEDIFF(Second, Min(CONVERT(VARCHAR(30), ([Visitor].[ArrivalDateTime]), 108) ), Max(CONVERT(VARCHAR(30), ([Visitor].[DepartureDateTime]), 108) )) AS TC9
FROM
[dbo].[Client] [Client]
JOIN [dbo].[Visitor] [Visitor] ON [Client].[Id] = [Visitor].[ClientId]
JOIN [dbo].[Location] [Location] ON [Visitor].[LocationId] = [Location].[Id]
WHERE
( [Client].[Name] = @Param )
AND
( cast([Visitor].[Arrivaldatetime] as date) between cast(getdate()-8 as date) and cast(getdate()-1 as date) )
GROUP BY
[Visitor].[ArrivalDateTime],
format(cast([Visitor].[ArrivalDateTime] as date),'dd MMM yyyy'),
FORMAT([Visitor].[ArrivalDateTime],'dddd'),
[Location].[VisitorTypeName],
[Visitor].[VisitorName],
[Location].[Name],
[Client].[Name]
ORDER BY
[Visitor].[ArrivalDateTime] ASC,
Min(CONVERT(VARCHAR(30), ([Visitor].[ArrivalDateTime]), 108) ) ASC
What I need now is a fortnightly report giving me a count, total duration (hh:mm) by Location Name and then by Visitor Name.
Thanks!