1
USE [RSConnect]
GO
/****** Object: StoredProcedure [dbo].[spTakeStudiesToMigrate] Script Date: 05/04/2016 16:24:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spTakeStudiesToMigrate]
(@RecordCount AS INT)
AS
BEGIN
update tblDaMiSource
set TransferStatus = 5
from (SELECT TOP (5) s.UIDStudy
FROM tblDaMiSource s WITH(NOLOCK)
WHERE NOT EXISTS (SELECT d.UIDStudy
FROM tblDaMiDestination d WITH(NOLOCK)
WHERE d.UIDStudy=s.UIDStudy and s.InstanceCount >= d.InstanceCount)
AND TransferStatus=2)
END