/****** Script for SelectTopNRows command from SSMS  ******/

--SELECT COUNT(*) 
--FROM (
SELECT *  INTO outpost.pilot_gillaspy.tbl_obs
FROM
(
SELECT --TOP 1000
 [PID] ,
 --[OBSID],
 [HDID] ,
 CAST([OBSDATE] as date) as OBSDATE,
 [OBSVALUE]

FROM [centricity_emr].[ML].[OBS]
WHERE HDID IN (55, 61, 2788)
  AND PID IN
    ( SELECT [PID]
     FROM [centricity_emr].[ML].[DOCUMENT]
     WHERE LOCOFCARE IN (1466943000000650, 1466943030000650, 1473775138000700, 1696769819014460) 
	 --GROUP BY PID, LOCOFCARE HAVING COUNT(*) > 2
 )
) as a