- Mike first visit goes to ER on 1/1/2014 :- output this data
- Mike goes again to ER on 1/3/2014 :- output this data
- Mike goes to Clinic on 1/20/2014 :- do not output this data
- Mike goes to Clinic on 5/2/2014 : output this data
- David first visit goes to Clinic on 3/3/2014 : output this data
- David goes back again to Clinic on 3/4/2014 : do not output this data
- David goes to ER on 3/15/2014 : output this data
NAME LOCATION DATE
MIKE ER 1/1/2014
MIKE ER 1/3/2014
MIKE CLINIC 1/20/2014
MIKE CLINIC 5/2/2014
DAVID CLINIC 3/3/2014
DAVID CLINIC 3/4/2014
DAVID ER 3/15/2014
NAME LOCATION DATE
MIKE ER 1/1/2014
MIKE ER 1/3/2014
MIKE CLINIC 5/2/2014
DAVID CLINIC 3/3/2014
DAVID ER 3/15/2014
SET NOCOUNT ON
GO
DECLARE @Init_DataSource TABLE
(
[NAME] VARCHAR(20)
,[DATE] DATE
,[LOCATION] VARCHAR(15)
)
INSERT INTO @Init_DataSource ([NAME], [DATE], [LOCATION])
VALUES ('MIKE', '1-1-2014', 'ER')
,('MIKE', '1-3-2014', 'ER')
,('MIKE', '1-20-2014', 'CLINIC')
,('MIKE', '5-2-2014', 'CLINIC')
,('DAVID', '3-3-2014', 'CLINIC')
,('DAVID', '3-4-2014', 'CLINIC')
,('DAVID', '3-15-2014', 'ER')
SELECT *
FROM @Init_DataSource
ORDER BY 1 DESC, 2 ASC
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.