
/****** Object:  StoredProcedure [dbo].[ApiPicturesProc]    Script Date: 07.09.2021 13:49:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[ApiPicturesProc]

	@Type AS INT
	, @ObjecId AS int
AS 
BEGIN
IF ( @Type =502)
BEGIN
select a.ID , a.Parent  , MimeType  , @Type ParentType ,ParentType ParentTypeName, Name--,'' Guid
	, convert(nvarchar(50), t.Guid) Guid
 from dbo.Attachments  a 
 JOIN dbo.Technologie t ON t.ID = a.Parent
 JOIN dbo.Technologie tt ON tt.TechnologiaWzor = t.ID
 JOIN dbo.Operacje op ON op.Technologia = tt.ID
 JOIN dbo.ApiProdActivities aa ON aa.OperationId = op.ID and aa.ActionId = @ObjecId
 JOIN dbo.ApiTypesTable ttab ON ttab.ErpType=a.ParentType and ttab.ApiType = 500
 END
 ELSE 
 BEGIN

	select a.ID , a.Parent  , MimeType  , @Type ParentType ,ParentType ParentTypeName, Name--,'' Guid
	, convert(nvarchar(50), t.Guid) Guid
 from dbo.Attachments  a 
 JOIN dbo.Technologie t ON t.ID = a.Parent
 JOIN dbo.ApiTypesTable ttab ON ttab.ErpType=a.ParentType and ttab.ApiType = @Type
where /*MimeType = 'image/pjpeg' and */
 Parent = @ObjecId;
END	
	
END



--select * from  dbo.ApiTypesTable
GO


