
IF EXISTS (Select * From dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getJustROFst]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP Procedure [dbo].[getJustROFst];
GO


/****** Object:  StoredProcedure [dbo].[getJustROFst]    Script Date: 5/4/2022 10:37:05 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

	
CREATE PROCEDURE [dbo].[getJustROFst]
(
	@ROFstID int
)
WITH EXECUTE AS OWNER
AS
	SELECT
		[ROFstID],
		[RODbID],
		[ROLookup],
		[Config],
		[DTS],
		[UserID],
		[LastChanged],
		(SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount],
		(SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount]
	FROM [ROFsts]
	WHERE [ROFstID]=@ROFstID
	RETURN
GO




IF EXISTS (Select * From dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getROFst]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP Procedure [dbo].[getROFst];
GO


/****** Object:  StoredProcedure [dbo].[getROFst]    Script Date: 5/4/2022 10:37:49 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

	
CREATE PROCEDURE [dbo].[getROFst]

(
	@ROFstID int
)
WITH EXECUTE AS OWNER
AS
	SELECT
		[ROFstID],
		[RODbID],
		[ROLookup],
		[Config],
		[DTS],
		[UserID],
		[LastChanged],
		(SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount],
		(SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount]
	FROM [ROFsts]
	WHERE [ROFstID]=@ROFstID

	SELECT
		[Associations].[AssociationID],
		[Associations].[VersionID],
		[Associations].[ROFstID],
		[Associations].[Config],
		[Associations].[DTS],
		[Associations].[UserID],
		[Associations].[LastChanged],
		[DocVersions].[FolderID] [DocVersion_FolderID],
		[DocVersions].[VersionType] [DocVersion_VersionType],
		[DocVersions].[Name] [DocVersion_Name],
		[DocVersions].[Title] [DocVersion_Title],
		[DocVersions].[ItemID] [DocVersion_ItemID],
		[DocVersions].[FormatID] [DocVersion_FormatID],
		[DocVersions].[Config] [DocVersion_Config],
		[DocVersions].[DTS] [DocVersion_DTS],
		[DocVersions].[UserID] [DocVersion_UserID]
	FROM [Associations]
		JOIN [DocVersions]  ON
			[DocVersions].[VersionID]=[Associations].[VersionID]
	WHERE
		[Associations].[ROFstID]=@ROFstID


	SELECT
		[Figures].[FigureID],
		[Figures].[ROFstID],
		[Figures].[ImageID],
		[Figures].[Config],
		[Figures].[DTS],
		[Figures].[UserID],
		[Figures].[LastChanged],
		[ROImages].[RODbID] [ROImage_RODbID],
		[ROImages].[FileName] [ROImage_FileName],
		[ROImages].[Content] [ROImage_Content],
		[ROImages].[Config] [ROImage_Config],
		[ROImages].[DTS] [ROImage_DTS],
		[ROImages].[UserID] [ROImage_UserID]
	FROM [Figures]
		JOIN [ROImages]  ON
			[ROImages].[ImageID]=[Figures].[ImageID]
	WHERE
		[Figures].[ROFstID]=@ROFstID

	RETURN
GO




IF EXISTS (Select * From dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getROFstByRODbID_DTS]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP Procedure [dbo].[getROFstByRODbID_DTS];
GO


/****** Object:  StoredProcedure [dbo].[getROFstByRODbID_DTS]    Script Date: 5/4/2022 10:46:34 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

	
CREATE PROCEDURE [dbo].[getROFstByRODbID_DTS]
(
	@RODbID int,
	@DTS datetime
)
WITH EXECUTE AS OWNER
AS
	SELECT
		[ROFstID],
		[RODbID],
		[ROLookup],
		[Config],
		[DTS],
		[UserID],
		[LastChanged],
		(SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount],
		(SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount]
	FROM [ROFsts]
	WHERE [RODbID]=@RODbID AND [DTS]=@DTS


	RETURN
GO




IF EXISTS (Select * From dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getROFsts]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP Procedure [dbo].[getROFsts];
GO

/****** Object:  StoredProcedure [dbo].[getROFsts]    Script Date: 5/4/2022 10:49:07 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

	
CREATE PROCEDURE [dbo].[getROFsts]

WITH EXECUTE AS OWNER
AS
	SELECT
		[ROFstID],
		[RODbID],
		[ROLookup],
		[Config],
		[DTS],
		[UserID],
		[LastChanged],
		(SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount],
		(SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount]
	FROM [ROFsts]
	RETURN
GO




IF EXISTS (Select * From dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[getROFstsByRODbID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP Procedure [dbo].[getROFstsByRODbID];
GO

/****** Object:  StoredProcedure [dbo].[getROFstsByRODbID]    Script Date: 5/4/2022 10:50:14 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

	
CREATE PROCEDURE [dbo].[getROFstsByRODbID]

(
	@RODbID int
)
WITH EXECUTE AS OWNER
AS

	SELECT
		[ROFsts].[ROFstID],
		[ROFsts].[RODbID],
		[ROFsts].[ROLookup],
		[ROFsts].[Config],
		[ROFsts].[DTS],
		[ROFsts].[UserID],
		[ROFsts].[LastChanged],
		(SELECT COUNT(1) FROM [Associations] WHERE [Associations].[ROFstID]=[ROFsts].[ROFstID]) [AssociationCount],
		(SELECT COUNT(1) FROM [Figures] WHERE [Figures].[ROFstID]=[ROFsts].[ROFstID]) [FigureCount]
	FROM [ROFsts]
	WHERE
		[ROFsts].[RODbID]=@RODbID

	RETURN
GO




