
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
ALTER FUNCTION [dbo].[getSectionForDTP] 
(
	-- Add the parameters for the function here
	@titleId INT,
	@sectionId int,
	@dzialId int = NULL
)
RETURNS varchar(10)
AS
BEGIN
	-- Declare the return variable here
DECLARE @grzbiet varchar(10)
DECLARE @unknownGrzbiet varchar(10)
SET @unknownGrzbiet ='-?-'

-- AMT
	IF @titleId=1
		BEGIN 
			SET @grzbiet = 
				CASE 
					--Blok Reklama + Truck&Transport
					WHEN @sectionId=20 OR @sectionId=24 THEN 'B'	
					--Zoom
					WHEN @sectionId=26 THEN 'D'	
					--Ogloszenia
					WHEN @sectionId=25 THEN
						CASE 
							WHEN @dzialId IS NULL THEN @unknownGrzbiet
							WHEN @dzialId=1 OR @dzialId=2 OR @dzialId=3 OR @dzialId=4 THEN 'B'
							WHEN @dzialId=5 OR @dzialId=6 OR @dzialId=7 OR @dzialId=8 OR @dzialId=9 OR @dzialId=10 OR @dzialId=11 OR @dzialId=12 OR @dzialId=13 THEN 'D'
							ELSE @unknownGrzbiet
						END
					ELSE @unknownGrzbiet
				END
		END

	IF @titleId=2
		BEGIN 
			SET @grzbiet = @unknownGrzbiet
--				CASE 
--					--Blok Reklama + Truck&Transport
--					WHEN @sectionId=20 OR @sectionId=24 THEN 'B'	
--					--Zoom
--					WHEN @sectionId=26 THEN 'D'	
--					--Ogloszenia
--					WHEN @sectionId=25 THEN
--						CASE 
--							WHEN @dzialId IS NULL THEN '?'
--							WHEN @dzialId=1 OR @dzialId=2 OR @dzialId=3 OR @dzialId=4 THEN 'B'
--							WHEN @dzialId=5 OR @dzialId=6 OR @dzialId=7 OR @dzialId=8 OR @dzialId=9 OR @dzialId=10 OR @dzialId=11 OR @dzialId=12 OR @dzialId=13 THEN 'B'
--							ELSE '?'
--						END
--					ELSE '?'
--				END
		END

RETURN @grzbiet

END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

