Hi,
Maybe you can try this.
I have used your above example with an Union all, this way all duplicates will not be excluded. If you want de duplicates excluded, you use Union. In this case I would advice Union all, because there is not a unique value and you want to see all the rows.
CREATE TABLE #LOG
(
Name VARCHAR(10),
StartDate DATETIME,
Activity VARCHAR(10),
);
INSERT INTO #LOG
VALUES
('ABC', '2015-02-27 16:46:12.653', 'LogON'),
('ABC', '2015-02-27 18:46:12.653', 'LOGOFF'),
('PQR', '2015-02-27 17:46:12.653', 'LogON'),
('PQR', '2015-02-27 20:46:12.653', 'LOGOFF'),
('ABC', '2015-02-27 22:46:12.653', 'LogON'),
('ABC', '2015-02-27 22:48:12.653', 'LOGOFF');
CREATE TABLE #ACT
(
Name VARCHAR(10),
StartDate DATETime,
Activity VARCHAR(10),
);
INSERT INTO #ACT
VALUES
('ABC', '2015-02-27 16:49:12.653', 'XXX'),
('ABC', '2015-02-27 16:52:12.653', 'PPP'),
('ABC', '2015-02-27 20:46:12.653', 'MNO'),
('ABC', '2015-02-27 20:48:12.653', 'PQR');
SELECT Name,StartDate,Activity
FROM #LOG
UNION ALL
SELECT TOP (100) PERCENT Name,StartDate,Activity
FROM #ACT
ORDER BY Name,StartDate
Regards,
Reshma
Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered
No comments:
Post a Comment