I have the following 2 select statements which I would like to merge having the entry and exit times next to each other in table based on the Date column which must match.
SELECT NAME, SURNAME,IDENTIFIER, CONVERT(VARCHAR,(MIN(TRANSIT_DATE)),114) AS [ENTRY],'' AS [EXIT], CONVERT(VARCHAR(10),TRANSIT_DATE,103)AS [DATE]
FROM [10.230.0.15].[SCAT].[dbo].[HA_TRANSIT] a
WHERE STR_DIRECTION = 'Entry'
and a.IDENTIFIER = '20045619'
AND STR_TRANSIT_STATUS = 'Granted'
AND TRANSIT_DATE BETWEEN @CompleteSDate AND @CompleteEDate
GROUP BY NAME, SURNAME,IDENTIFIER,CONVERT(VARCHAR(10),TRANSIT_DATE,103)
SELECT NAME, SURNAME,IDENTIFIER, '' AS [ENTRY],CONVERT(VARCHAR,(MAX(TRANSIT_DATE)),114) AS [EXIT], CONVERT(VARCHAR(10),TRANSIT_DATE,103)AS [DATE]
FROM [10.230.0.15].[SCAT].[dbo].[HA_TRANSIT] a
WHERE STR_DIRECTION = 'Exit'
and a.IDENTIFIER = '20045619'
AND STR_TRANSIT_STATUS = 'Granted'
AND TRANSIT_DATE BETWEEN @CompleteSDate AND @CompleteEDate
GROUP BY NAME, SURNAME,IDENTIFIER,CONVERT(VARCHAR(10),TRANSIT_DATE,103)
RESULTS of Query 1 NAME SURNAME IDENTIFIER ENTRY EXIT DATE ANTONETTE COLEMAN 20045619 07:11:01:000 10/09/2013 ANTONETTE COLEMAN 20045619 06:58:58:000 11/09/2013 ANTONETTE COLEMAN 20045619 07:04:27:000 12/09/2013 ANTONETTE COLEMAN 20045619 07:02:48:000 13/09/2013 ANTONETTE COLEMAN 20045619 07:17:43:000 16/09/2013 ANTONETTE COLEMAN 20045619 06:54:35:000 17/09/2013 ANTONETTE COLEMAN 20045619 07:00:36:000 18/09/2013 ANTONETTE COLEMAN 20045619 06:57:33:000 19/09/2013
RESULTS of Query 2 NAME SURNAME IDENTIFIER ENTRY EXIT
DATE ANTONETTE COLEMAN 20045619 16:09:39:000 10/09/2013 ANTONETTE COLEMAN 20045619 16:01:19:000 11/09/2013 ANTONETTE COLEMAN 20045619 16:18:49:000 12/09/2013 ANTONETTE COLEMAN 20045619 16:04:28:000 13/09/2013 ANTONETTE COLEMAN 20045619 16:06:04:000 16/09/2013 ANTONETTE COLEMAN 20045619 16:05:30:000 17/09/2013 ANTONETTE COLEMAN 20045619 16:02:00:000 18/09/2013