/*
    Update-Schritte 5.11.18:

    1. Lokale Ausführungszeit und Zeitzone in Aufgabenplänen hinzufügen

*/
GO

UPDATE system.tPipelineSchedules
SET ScheduleDetailsJSON = REPLACE(
    JSON_MODIFY(
        JSON_MODIFY(
            ScheduleDetailsJSON,
            '$.ExecutionLocalTime',
            FORMAT(DATEADD(HOUR, 2, CAST(JSON_VALUE(ScheduleDetailsJSON, '$.ExecutionTime') AS DATETIMEOFFSET)), 'HH:mm:ss')
        ),
        '$.TimeZoneId',
        'Europe/Berlin'
    ),
    '/',
    '/'
)
WHERE
    ISJSON(ScheduleDetailsJSON) = 1 AND
    JSON_VALUE(ScheduleDetailsJSON, '$.ExecutionLocalTime') IS NULL AND
    JSON_VALUE(ScheduleDetailsJSON, '$.TimeZoneId') IS NULL
GO


 
DROP PROCEDURE IF EXISTS dbo.sx_pf_POST_ProductLine;
GO

/*
	POST Operation for ProductLine
	Not existing ProductLine will be created, existing gets an Update
	If attributes passed with value <#NV>, it will be ignored during the update and maintain the existing value, during insert the attribute is created empty

	Gerd Tautenhahn for Saxess Software GmbH
	Last modified: 10/2022 for OCT 5.8

	Test call
	1. Empty FactoryID / ProductLineID  => 404 Not Found
	2. TransactionUsername not determined for User => 403 Forbidden
	3. Username does not have write access to ProductLine => 401 Unauthorized
	3. Username does not have write access to Factory on Create => 401 Unauthorized
	5. Non exists Factory / ProductLine keys => 404 Not Found
	6. ProductLine created => 201 Created
	7. ProductLine updated => 200 OK

	DECLARE  @RC						INT
			,@Username					NVARCHAR(255) = 'SQL'
			,@ProductLineID				NVARCHAR(255) = 'ee'
			,@FactoryID					NVARCHAR(255) = 'ZT'
			,@NameShort					NVARCHAR(255) = ''
			,@NameLong					NVARCHAR(255) = ''
			,@CommentUser				NVARCHAR(255) = ''
			,@CommentDev				NVARCHAR(255) = ''
			,@ResponsiblePerson			NVARCHAR(255) = ''
			,@ImageName					NVARCHAR(255) = ''
			,@DefaultTemplate			NVARCHAR(255) = ''
			,@GlobalAttributeSource1	NVARCHAR(255) = ''
			,@GlobalAttributeAlias1		NVARCHAR(255) = ''
			,@GlobalAttributeSource2	NVARCHAR(255) = ''
			,@GlobalAttributeAlias2		NVARCHAR(255) = ''
			,@GlobalAttributeSource3	NVARCHAR(255) = ''
			,@GlobalAttributeAlias3		NVARCHAR(255) = ''
			,@GlobalAttributeSource4	NVARCHAR(255) = ''
			,@GlobalAttributeAlias4		NVARCHAR(255) = ''
			,@GlobalAttributeSource5	NVARCHAR(255) = ''
			,@GlobalAttributeAlias5		NVARCHAR(255) = ''
			,@GlobalAttributeSource6	NVARCHAR(255) = ''
			,@GlobalAttributeAlias6		NVARCHAR(255) = ''
			,@GlobalAttributeSource7	NVARCHAR(255) = ''
			,@GlobalAttributeAlias7		NVARCHAR(255) = ''
			,@GlobalAttributeSource8	NVARCHAR(255) = ''
			,@GlobalAttributeAlias8		NVARCHAR(255) = ''
			,@GlobalAttributeSource9	NVARCHAR(255) = ''
			,@GlobalAttributeAlias9		NVARCHAR(255) = ''
			,@GlobalAttributeSource10	NVARCHAR(255) = ''
			,@GlobalAttributeAlias10	NVARCHAR(255) = ''
			,@GlobalAttributeSource11	NVARCHAR(255) = ''
			,@GlobalAttributeAlias11	NVARCHAR(255) = ''
			,@GlobalAttributeSource12	NVARCHAR(255) = ''
			,@GlobalAttributeAlias12	NVARCHAR(255) = ''
			,@GlobalAttributeSource13	NVARCHAR(255) = ''
			,@GlobalAttributeAlias13	NVARCHAR(255) = ''
			,@GlobalAttributeSource14	NVARCHAR(255) = ''
			,@GlobalAttributeAlias14	NVARCHAR(255) = ''
			,@GlobalAttributeSource15	NVARCHAR(255) = ''
			,@GlobalAttributeAlias15	NVARCHAR(255) = ''
			,@GlobalAttributeSource16	NVARCHAR(255) = ''
			,@GlobalAttributeAlias16	NVARCHAR(255) = ''
			,@GlobalAttributeSource17	NVARCHAR(255) = ''
			,@GlobalAttributeAlias17	NVARCHAR(255) = ''
			,@GlobalAttributeSource18	NVARCHAR(255) = ''
			,@GlobalAttributeAlias18	NVARCHAR(255) = ''
			,@GlobalAttributeSource19	NVARCHAR(255) = ''
			,@GlobalAttributeAlias19	NVARCHAR(255) = ''
			,@GlobalAttributeSource20	NVARCHAR(255) = ''
			,@GlobalAttributeAlias20	NVARCHAR(255) = ''
			,@GlobalAttributeSource21	NVARCHAR(255) = ''
			,@GlobalAttributeAlias21	NVARCHAR(255) = ''
			,@GlobalAttributeSource22	NVARCHAR(255) = ''
			,@GlobalAttributeAlias22	NVARCHAR(255) = ''
			,@GlobalAttributeSource23	NVARCHAR(255) = ''
			,@GlobalAttributeAlias23	NVARCHAR(255) = ''
			,@GlobalAttributeSource24	NVARCHAR(255) = ''
			,@GlobalAttributeAlias24	NVARCHAR(255) = ''
			,@GlobalAttributeSource25	NVARCHAR(255) = ''
			,@GlobalAttributeAlias25	NVARCHAR(255) = ''
			,@LayoutJSON				NVARCHAR(MAX) = ''

	EXECUTE @RC = dbo.sx_pf_POST_ProductLine @Username, @ProductLineID, @FactoryID, @NameShort, @NameLong, @CommentUser, @CommentDev, @ResponsiblePerson, @ImageName, @DefaultTemplate, 
			@GlobalAttributeSource1, @GlobalAttributeAlias1, @GlobalAttributeSource2, @GlobalAttributeAlias2, @GlobalAttributeSource3, @GlobalAttributeAlias3, @GlobalAttributeSource4, 
			@GlobalAttributeAlias4, @GlobalAttributeSource5, @GlobalAttributeAlias5, @GlobalAttributeSource6, @GlobalAttributeAlias6, @GlobalAttributeSource7, @GlobalAttributeAlias7, 
			@GlobalAttributeSource8, @GlobalAttributeAlias8, @GlobalAttributeSource9, @GlobalAttributeAlias9, @GlobalAttributeSource10, @GlobalAttributeAlias10, @GlobalAttributeSource11, 
			@GlobalAttributeAlias11, @GlobalAttributeSource12, @GlobalAttributeAlias12, @GlobalAttributeSource13, @GlobalAttributeAlias13, @GlobalAttributeSource14, @GlobalAttributeAlias14, 
			@GlobalAttributeSource15, @GlobalAttributeAlias15, @GlobalAttributeSource16, @GlobalAttributeAlias16, @GlobalAttributeSource17, @GlobalAttributeAlias17, @GlobalAttributeSource18, 
			@GlobalAttributeAlias18, @GlobalAttributeSource19, @GlobalAttributeAlias19, @GlobalAttributeSource20, @GlobalAttributeAlias20, @GlobalAttributeSource21, @GlobalAttributeAlias21, 
			@GlobalAttributeSource22, @GlobalAttributeAlias22, @GlobalAttributeSource23, @GlobalAttributeAlias23, @GlobalAttributeSource24, @GlobalAttributeAlias24, @GlobalAttributeSource25, 
			@GlobalAttributeAlias25,
			@LayoutJSON
	PRINT @RC

	Testcall Documentation
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'dbo', 'PROCEDURE', 'sx_pf_POST_ProductLine',NULL,NULL)
		UNION ALL
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'dbo', 'PROCEDURE', 'sx_pf_POST_ProductLine','PARAMETER',NULL)
*/

CREATE PROCEDURE dbo.sx_pf_POST_ProductLine
	@Username					NVARCHAR(255),
	@ProductLineID				NVARCHAR(255),
	@FactoryID					NVARCHAR(255),
	@NameShort					NVARCHAR(255),
	@NameLong					NVARCHAR(255),
	@CommentUser				NVARCHAR(MAX),
	@CommentDev					NVARCHAR(MAX),
	@ResponsiblePerson			NVARCHAR(255),
	@ImageName					NVARCHAR(255),
	@DefaultTemplate			NVARCHAR(255),
	@GlobalAttributeSource1		NVARCHAR(255),
	@GlobalAttributeAlias1		NVARCHAR(255),
	@GlobalAttributeSource2		NVARCHAR(255),
	@GlobalAttributeAlias2		NVARCHAR(255),
	@GlobalAttributeSource3		NVARCHAR(255),
	@GlobalAttributeAlias3		NVARCHAR(255),
	@GlobalAttributeSource4		NVARCHAR(255),
	@GlobalAttributeAlias4		NVARCHAR(255),
	@GlobalAttributeSource5		NVARCHAR(255),
	@GlobalAttributeAlias5		NVARCHAR(255),
	@GlobalAttributeSource6		NVARCHAR(255),
	@GlobalAttributeAlias6		NVARCHAR(255),
	@GlobalAttributeSource7		NVARCHAR(255),
	@GlobalAttributeAlias7		NVARCHAR(255),
	@GlobalAttributeSource8		NVARCHAR(255),
	@GlobalAttributeAlias8		NVARCHAR(255),
	@GlobalAttributeSource9		NVARCHAR(255),
	@GlobalAttributeAlias9		NVARCHAR(255),
	@GlobalAttributeSource10	NVARCHAR(255),
	@GlobalAttributeAlias10		NVARCHAR(255),
	@GlobalAttributeSource11	NVARCHAR(255),
	@GlobalAttributeAlias11		NVARCHAR(255),
	@GlobalAttributeSource12	NVARCHAR(255),
	@GlobalAttributeAlias12		NVARCHAR(255),
	@GlobalAttributeSource13	NVARCHAR(255),
	@GlobalAttributeAlias13		NVARCHAR(255),
	@GlobalAttributeSource14	NVARCHAR(255),
	@GlobalAttributeAlias14		NVARCHAR(255),
	@GlobalAttributeSource15	NVARCHAR(255),
	@GlobalAttributeAlias15		NVARCHAR(255),
	@GlobalAttributeSource16	NVARCHAR(255),
	@GlobalAttributeAlias16		NVARCHAR(255),
	@GlobalAttributeSource17	NVARCHAR(255),
	@GlobalAttributeAlias17		NVARCHAR(255),
	@GlobalAttributeSource18	NVARCHAR(255),
	@GlobalAttributeAlias18		NVARCHAR(255),
	@GlobalAttributeSource19	NVARCHAR(255),
	@GlobalAttributeAlias19		NVARCHAR(255),
	@GlobalAttributeSource20	NVARCHAR(255),
	@GlobalAttributeAlias20		NVARCHAR(255),
	@GlobalAttributeSource21	NVARCHAR(255),
	@GlobalAttributeAlias21		NVARCHAR(255),
	@GlobalAttributeSource22	NVARCHAR(255),
	@GlobalAttributeAlias22		NVARCHAR(255),
	@GlobalAttributeSource23	NVARCHAR(255),
	@GlobalAttributeAlias23		NVARCHAR(255),
	@GlobalAttributeSource24	NVARCHAR(255),
	@GlobalAttributeAlias24		NVARCHAR(255),
	@GlobalAttributeSource25	NVARCHAR(255),
	@GlobalAttributeAlias25		NVARCHAR(255),
	@LayoutJSON					NVARCHAR(MAX) = NULL -- Kompatibilität für alte Versionen
AS 
BEGIN
	SET NOCOUNT ON;

	DECLARE @TransactUsername	NVARCHAR(255)= N'';
	DECLARE @FactoryKey			INT = 0;
	DECLARE @ProductLineKey		INT = 0;
	DECLARE @ProcedureName		NVARCHAR (255) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
	DECLARE @ParameterString	NVARCHAR (MAX) = 
			N''''	   + ISNULL(@Username,					N'NULL')
			+ N''',''' + ISNULL(@ProductLineID,				N'NULL') + N''',''' + ISNULL(@FactoryID,				N'NULL') + N''',''' + ISNULL(@NameShort,				N'NULL')
			+ N''',''' + ISNULL(@NameLong,					N'NULL') + N''',''' + ISNULL(@CommentUser,				N'NULL') + N''',''' + ISNULL(@CommentDev,				N'NULL') 
			+ N''',''' + ISNULL(@ResponsiblePerson,			N'NULL') + N''',''' + ISNULL(@ImageName,				N'NULL') + N''',''' + ISNULL(@DefaultTemplate,			N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource1,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias1,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource2,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias2,		N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource3,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias3,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource4,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias4,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource5,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias5,		N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource6,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias6,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource7,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias7,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource8,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias8,		N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource9,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias9,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource10,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias10,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource11,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias11,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource12,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias12,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource13,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias13,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource14,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias14,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource15,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias15,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource16,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias16,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource17,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias17,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource18,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias18,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource19,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias19,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource20,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias20,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource21,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias21,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource22,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias22,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource23,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeAlias23,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeSource24,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias24,	N'NULL') 
			+ N''',''' + ISNULL(@GlobalAttributeSource25,	N'NULL') + N''',''' + ISNULL(@GlobalAttributeAlias25,	N'NULL') + N'''';
	DECLARE @EffectedRows		INT				= 0;				-- SET during Execution
	DECLARE @ResultCode			INT				= 501;				-- SET during Execution
	DECLARE @TimestampCall		DATETIME		= GETUTCDATE();
	DECLARE @Comment			NVARCHAR(2000)	= N'';				-- SET during Execution

	-- STEP 0.1 - NULL Protection
	IF @Username				IS NULL SET @Username					= N'';
	IF @ProductLineID			IS NULL SET @ProductLineID				= N'';
	IF @FactoryID				IS NULL SET @FactoryID					= N'';
	IF @NameShort				IS NULL SET @NameShort					= N'';
	IF @NameLong				IS NULL SET @NameLong					= N'';
	IF @CommentUser				IS NULL SET @CommentUser				= N'';
	IF @CommentDev				IS NULL SET @CommentDev					= N'';
	IF @ResponsiblePerson		IS NULL SET @ResponsiblePerson			= N'';
	IF @ImageName				IS NULL SET @ImageName					= N'';
	IF @DefaultTemplate			IS NULL SET @DefaultTemplate			= N'';
	IF @GlobalAttributeSource1	IS NULL SET @GlobalAttributeSource1		= N'';
	IF @GlobalAttributeAlias1	IS NULL SET @GlobalAttributeAlias1		= N'';
	IF @GlobalAttributeSource2	IS NULL SET @GlobalAttributeSource2		= N'';
	IF @GlobalAttributeAlias2	IS NULL SET @GlobalAttributeAlias2		= N'';
	IF @GlobalAttributeSource3	IS NULL SET @GlobalAttributeSource3		= N'';
	IF @GlobalAttributeAlias3	IS NULL SET @GlobalAttributeAlias3		= N'';
	IF @GlobalAttributeSource4	IS NULL SET @GlobalAttributeSource4		= N'';
	IF @GlobalAttributeAlias4	IS NULL SET @GlobalAttributeAlias4		= N'';
	IF @GlobalAttributeSource5	IS NULL SET @GlobalAttributeSource5		= N'';
	IF @GlobalAttributeAlias5	IS NULL SET @GlobalAttributeAlias5		= N'';
	IF @GlobalAttributeSource6	IS NULL SET @GlobalAttributeSource6		= N'';
	IF @GlobalAttributeAlias6	IS NULL SET @GlobalAttributeAlias6		= N'';
	IF @GlobalAttributeSource7	IS NULL SET @GlobalAttributeSource7		= N'';
	IF @GlobalAttributeAlias7	IS NULL SET @GlobalAttributeAlias7		= N'';
	IF @GlobalAttributeSource8	IS NULL SET @GlobalAttributeSource8		= N'';
	IF @GlobalAttributeAlias8	IS NULL SET @GlobalAttributeAlias8		= N'';
	IF @GlobalAttributeSource9	IS NULL SET @GlobalAttributeSource9		= N'';
	IF @GlobalAttributeAlias9	IS NULL SET @GlobalAttributeAlias9		= N'';
	IF @GlobalAttributeSource10 IS NULL SET @GlobalAttributeSource10	= N'';
	IF @GlobalAttributeAlias10	IS NULL SET @GlobalAttributeAlias10		= N'';
	IF @GlobalAttributeSource11 IS NULL SET @GlobalAttributeSource11	= N'';
	IF @GlobalAttributeAlias11	IS NULL SET @GlobalAttributeAlias11		= N'';
	IF @GlobalAttributeSource12 IS NULL SET @GlobalAttributeSource12	= N'';
	IF @GlobalAttributeAlias12	IS NULL SET @GlobalAttributeAlias12		= N'';
	IF @GlobalAttributeSource13 IS NULL SET @GlobalAttributeSource13	= N'';
	IF @GlobalAttributeAlias13	IS NULL SET @GlobalAttributeAlias13		= N'';
	IF @GlobalAttributeSource14 IS NULL SET @GlobalAttributeSource14	= N'';
	IF @GlobalAttributeAlias14	IS NULL SET @GlobalAttributeAlias14		= N'';
	IF @GlobalAttributeSource15 IS NULL SET @GlobalAttributeSource15	= N'';
	IF @GlobalAttributeAlias15	IS NULL SET @GlobalAttributeAlias15		= N'';
	IF @GlobalAttributeSource16 IS NULL SET @GlobalAttributeSource16	= N'';
	IF @GlobalAttributeAlias16	IS NULL SET @GlobalAttributeAlias16		= N'';
	IF @GlobalAttributeSource17 IS NULL SET @GlobalAttributeSource17	= N'';
	IF @GlobalAttributeAlias17	IS NULL SET @GlobalAttributeAlias17		= N'';
	IF @GlobalAttributeSource18 IS NULL SET @GlobalAttributeSource18	= N'';
	IF @GlobalAttributeAlias18	IS NULL SET @GlobalAttributeAlias18		= N'';
	IF @GlobalAttributeSource19 IS NULL SET @GlobalAttributeSource19	= N'';
	IF @GlobalAttributeAlias19	IS NULL SET @GlobalAttributeAlias19		= N'';
	IF @GlobalAttributeSource20 IS NULL SET @GlobalAttributeSource20	= N'';
	IF @GlobalAttributeAlias20	IS NULL SET @GlobalAttributeAlias20		= N'';
	IF @GlobalAttributeSource21 IS NULL SET @GlobalAttributeSource21	= N'';
	IF @GlobalAttributeAlias21	IS NULL SET @GlobalAttributeAlias21		= N'';
	IF @GlobalAttributeSource22 IS NULL SET @GlobalAttributeSource22	= N'';
	IF @GlobalAttributeAlias22	IS NULL SET @GlobalAttributeAlias22		= N'';
	IF @GlobalAttributeSource23 IS NULL SET @GlobalAttributeSource23	= N'';
	IF @GlobalAttributeAlias23	IS NULL SET @GlobalAttributeAlias23		= N'';
	IF @GlobalAttributeSource24 IS NULL SET @GlobalAttributeSource24	= N'';
	IF @GlobalAttributeAlias24	IS NULL SET @GlobalAttributeAlias24		= N'';
	IF @GlobalAttributeSource25 IS NULL SET @GlobalAttributeSource25	= N'';
	IF @GlobalAttributeAlias25	IS NULL SET @GlobalAttributeAlias25		= N'';
	IF @LayoutJSON				IS NULL SET @LayoutJSON					= N'';

	BEGIN TRY
		BEGIN TRANSACTION sx_pf_POST_ProductLine;
		
		-- STEP 0.2 - Protect input parameters	
		SET @ProductLineID			= dbo.sx_pf_pProtectID     (@ProductLineID);
		SET @FactoryID				= dbo.sx_pf_pProtectID	   (@FactoryID);
		SET @NameShort				= dbo.sx_pf_pProtectString (@NameShort);
		SET @NameLong				= dbo.sx_pf_pProtectString (@NameLong);
		SET @CommentUser			= dbo.sx_pf_pProtectString (@CommentUser);
		SET @CommentDev				= dbo.sx_pf_pProtectString (@CommentDev);
		SET @ResponsiblePerson		= dbo.sx_pf_pProtectString (@ResponsiblePerson);
		SET @ImageName				= dbo.sx_pf_pProtectString (@ImageName);
		SET @DefaultTemplate		= dbo.sx_pf_pProtectString (@DefaultTemplate);
		SET @GlobalAttributeAlias1	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias1);
		SET @GlobalAttributeAlias2	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias2);
		SET @GlobalAttributeAlias3	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias3);
		SET @GlobalAttributeAlias4	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias4);
		SET @GlobalAttributeAlias5	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias5);
		SET @GlobalAttributeAlias6	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias6);
		SET @GlobalAttributeAlias7	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias7);
		SET @GlobalAttributeAlias8	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias8);
		SET @GlobalAttributeAlias9	= dbo.sx_pf_pProtectString (@GlobalAttributeAlias9);
		SET @GlobalAttributeAlias10 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias10);
		SET @GlobalAttributeAlias11 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias11);
		SET @GlobalAttributeAlias12 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias12);
		SET @GlobalAttributeAlias13 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias13);
		SET @GlobalAttributeAlias14 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias14);
		SET @GlobalAttributeAlias15 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias15);
		SET @GlobalAttributeAlias16 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias16);
		SET @GlobalAttributeAlias17 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias17);
		SET @GlobalAttributeAlias18 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias18);
		SET @GlobalAttributeAlias19 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias19);
		SET @GlobalAttributeAlias20 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias20);
		SET @GlobalAttributeAlias21 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias21);
		SET @GlobalAttributeAlias22 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias22);
		SET @GlobalAttributeAlias23 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias23);
		SET @GlobalAttributeAlias24 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias24);
		SET @GlobalAttributeAlias25 = dbo.sx_pf_pProtectString (@GlobalAttributeAlias25);
		SET @LayoutJSON				= dbo.sx_pf_pProtectString (@LayoutJSON);

		IF @GlobalAttributeSource1	!='<#NV>' SET @GlobalAttributeSource1  = dbo.sx_pf_pProtectID (@GlobalAttributeSource1)
		IF @GlobalAttributeSource2	!='<#NV>' SET @GlobalAttributeSource2  = dbo.sx_pf_pProtectID (@GlobalAttributeSource2)
		IF @GlobalAttributeSource3	!='<#NV>' SET @GlobalAttributeSource3  = dbo.sx_pf_pProtectID (@GlobalAttributeSource3)
		IF @GlobalAttributeSource4	!='<#NV>' SET @GlobalAttributeSource4  = dbo.sx_pf_pProtectID (@GlobalAttributeSource4)
		IF @GlobalAttributeSource5	!='<#NV>' SET @GlobalAttributeSource5  = dbo.sx_pf_pProtectID (@GlobalAttributeSource5)
		IF @GlobalAttributeSource6	!='<#NV>' SET @GlobalAttributeSource6  = dbo.sx_pf_pProtectID (@GlobalAttributeSource6)
		IF @GlobalAttributeSource7	!='<#NV>' SET @GlobalAttributeSource7  = dbo.sx_pf_pProtectID (@GlobalAttributeSource7)
		IF @GlobalAttributeSource8	!='<#NV>' SET @GlobalAttributeSource8  = dbo.sx_pf_pProtectID (@GlobalAttributeSource8)
		IF @GlobalAttributeSource9	!='<#NV>' SET @GlobalAttributeSource9  = dbo.sx_pf_pProtectID (@GlobalAttributeSource9)
		IF @GlobalAttributeSource10 !='<#NV>' SET @GlobalAttributeSource10 = dbo.sx_pf_pProtectID (@GlobalAttributeSource10)
		IF @GlobalAttributeSource11 !='<#NV>' SET @GlobalAttributeSource11 = dbo.sx_pf_pProtectID (@GlobalAttributeSource11)
		IF @GlobalAttributeSource12 !='<#NV>' SET @GlobalAttributeSource12 = dbo.sx_pf_pProtectID (@GlobalAttributeSource12)
		IF @GlobalAttributeSource13 !='<#NV>' SET @GlobalAttributeSource13 = dbo.sx_pf_pProtectID (@GlobalAttributeSource13)
		IF @GlobalAttributeSource14 !='<#NV>' SET @GlobalAttributeSource14 = dbo.sx_pf_pProtectID (@GlobalAttributeSource14)
		IF @GlobalAttributeSource15 !='<#NV>' SET @GlobalAttributeSource15 = dbo.sx_pf_pProtectID (@GlobalAttributeSource15)
		IF @GlobalAttributeSource16 !='<#NV>' SET @GlobalAttributeSource16 = dbo.sx_pf_pProtectID (@GlobalAttributeSource16)
		IF @GlobalAttributeSource17 !='<#NV>' SET @GlobalAttributeSource17 = dbo.sx_pf_pProtectID (@GlobalAttributeSource17)
		IF @GlobalAttributeSource18 !='<#NV>' SET @GlobalAttributeSource18 = dbo.sx_pf_pProtectID (@GlobalAttributeSource18)
		IF @GlobalAttributeSource19 !='<#NV>' SET @GlobalAttributeSource19 = dbo.sx_pf_pProtectID (@GlobalAttributeSource19)
		IF @GlobalAttributeSource20 !='<#NV>' SET @GlobalAttributeSource20 = dbo.sx_pf_pProtectID (@GlobalAttributeSource20)
		IF @GlobalAttributeSource21 !='<#NV>' SET @GlobalAttributeSource21 = dbo.sx_pf_pProtectID (@GlobalAttributeSource21)
		IF @GlobalAttributeSource22 !='<#NV>' SET @GlobalAttributeSource22 = dbo.sx_pf_pProtectID (@GlobalAttributeSource22)
		IF @GlobalAttributeSource23 !='<#NV>' SET @GlobalAttributeSource23 = dbo.sx_pf_pProtectID (@GlobalAttributeSource23)
		IF @GlobalAttributeSource24 !='<#NV>' SET @GlobalAttributeSource24 = dbo.sx_pf_pProtectID (@GlobalAttributeSource24)
		IF @GlobalAttributeSource25 !='<#NV>' SET @GlobalAttributeSource25 = dbo.sx_pf_pProtectID (@GlobalAttributeSource25)
		
		IF	@FactoryID	= N'' 
			OR @ProductLineID = N''
		BEGIN
			SET @ResultCode = 404;
			RAISERROR('Empty input parameters', 16, 10);
		END;

		-- STEP 1.1 - Determine transaction user
		SELECT @TransactUsername = dbo.sx_pf_Determine_TransactionUsername (@Username);

		IF @TransactUsername  = N'403' 
		BEGIN
			SET @ResultCode = 403;
			RAISERROR('Transaction user don`t exists', 16, 10);
		END;

		-- STEP 1.2 - Determine keys
		SELECT @FactoryKey = FactoryKey FROM planning.tdFactories WHERE FactoryID = @FactoryID;
		SELECT @ProductLineKey = ProductLineKey FROM planning.tdProductLines WHERE FactoryKey = @FactoryKey AND ProductLineID = @ProductLineID;

		IF @FactoryKey = 0
		BEGIN
			SET @ResultCode = 404;
			RAISERROR('Keys don`t exists', 16, 10);
		END;
		
		-- STEP 2 - Check rights
		IF @ProductLineKey = 0
			EXEC @ResultCode = sx_pf_pGET_FactoryWriteRight @TransactUsername, @FactoryID;
		ELSE
			EXEC @ResultCode = sx_pf_pGET_ProductLineWriteRight @TransactUsername, @FactoryID, @ProductLineID;
		
		IF @ResultCode <> 200
			RAISERROR('Invalid rights', 16, 10);

		-- STEP 3.1 - If Product Line does not yet exist, it will be created in minimal configuration		
		IF @ProductLineKey = 0
		BEGIN

			DECLARE @Keys AS TABLE ([Key] INT NOT NULL);

			INSERT INTO planning.tdProductLines (FactoryKey, ProductLineID, FactoryID, NameShort, NameLong, CommentUser, CommentDev, ResponsiblePerson, ImageName, DefaultTemplate
				, GlobalAttributeSource1,  GlobalAttributeAlias1,  GlobalAttributeSource2,  GlobalAttributeAlias2,  GlobalAttributeSource3,  GlobalAttributeAlias3,  GlobalAttributeSource4,  GlobalAttributeAlias4,  GlobalAttributeSource5,  GlobalAttributeAlias5
				, GlobalAttributeSource6,  GlobalAttributeAlias6,  GlobalAttributeSource7,  GlobalAttributeAlias7,  GlobalAttributeSource8,  GlobalAttributeAlias8,  GlobalAttributeSource9,  GlobalAttributeAlias9,  GlobalAttributeSource10, GlobalAttributeAlias10
				, GlobalAttributeSource11, GlobalAttributeAlias11, GlobalAttributeSource12, GlobalAttributeAlias12, GlobalAttributeSource13, GlobalAttributeAlias13, GlobalAttributeSource14, GlobalAttributeAlias14, GlobalAttributeSource15, GlobalAttributeAlias15
				, GlobalAttributeSource16, GlobalAttributeAlias16, GlobalAttributeSource17, GlobalAttributeAlias17, GlobalAttributeSource18, GlobalAttributeAlias18, GlobalAttributeSource19, GlobalAttributeAlias19, GlobalAttributeSource20, GlobalAttributeAlias20
				, GlobalAttributeSource21, GlobalAttributeAlias21, GlobalAttributeSource22, GlobalAttributeAlias22, GlobalAttributeSource23, GlobalAttributeAlias23, GlobalAttributeSource24, GlobalAttributeAlias24, GlobalAttributeSource25, GlobalAttributeAlias25
				, LayoutJSON
			) 
			OUTPUT INSERTED.ProductLineKey INTO @Keys([Key])  
			VALUES (@FactoryKey, @ProductLineID, @FactoryID, @NameShort, '', '', '', '', '', ''
				, '', '', '', '', '', '', '', '', '', ''
				, '', '', '', '', '', '', '', '', '', ''
				, '', '', '', '', '', '', '', '', '', ''
				, '', '', '', '', '', '', '', '', '', ''
				, '', '', '', '', '', '', '', '', '', ''
				, @LayoutJSON
			);

			SELECT TOP (1) @ProductLineKey = [Key] FROM @Keys ORDER BY [Key];
			
			SET @EffectedRows = 1;
			SET @Resultcode	  = 201;
		END;

		-- STEP 3.2 - Update values
		UPDATE planning.tdProductLines
		SET 
			NameShort					= IIF(@NameShort				= N'<#NV>', NameShort,				 @NameShort)
			, NameLong					= IIF(@NameLong					= N'<#NV>', NameLong,				 @NameLong)
			, CommentUser				= IIF(@CommentUser				= N'<#NV>', CommentUser,			 @CommentUser)
			, CommentDev				= IIF(@CommentDev				= N'<#NV>', CommentDev,				 @CommentDev)
			, ResponsiblePerson			= IIF(@ResponsiblePerson		= N'<#NV>', ResponsiblePerson,		 @ResponsiblePerson)
			, ImageName					= IIF(@ImageName				= N'<#NV>', ImageName,				 @ImageName)
			, DefaultTemplate			= IIF(@DefaultTemplate			= N'<#NV>', DefaultTemplate,		 @DefaultTemplate)
			, GlobalAttributeSource1	= IIF(@GlobalAttributeSource1	= N'<#NV>', GlobalAttributeSource1,	 @GlobalAttributeSource1)
			, GlobalAttributeAlias1		= IIF(@GlobalAttributeAlias1	= N'<#NV>', GlobalAttributeAlias1,	 @GlobalAttributeAlias1)			
			, GlobalAttributeSource2	= IIF(@GlobalAttributeSource2	= N'<#NV>', GlobalAttributeSource2,	 @GlobalAttributeSource2)
			, GlobalAttributeAlias2		= IIF(@GlobalAttributeAlias2	= N'<#NV>', GlobalAttributeAlias2,	 @GlobalAttributeAlias2)
			, GlobalAttributeSource3	= IIF(@GlobalAttributeSource3	= N'<#NV>', GlobalAttributeSource3,	 @GlobalAttributeSource3)
			, GlobalAttributeAlias3		= IIF(@GlobalAttributeAlias3	= N'<#NV>', GlobalAttributeAlias3,	 @GlobalAttributeAlias3)
			, GlobalAttributeSource4	= IIF(@GlobalAttributeSource4	= N'<#NV>', GlobalAttributeSource4,	 @GlobalAttributeSource4)
			, GlobalAttributeAlias4		= IIF(@GlobalAttributeAlias4	= N'<#NV>', GlobalAttributeAlias4,	 @GlobalAttributeAlias4)
			, GlobalAttributeSource5	= IIF(@GlobalAttributeSource5	= N'<#NV>', GlobalAttributeSource5,	 @GlobalAttributeSource5)
			, GlobalAttributeAlias5		= IIF(@GlobalAttributeAlias5	= N'<#NV>', GlobalAttributeAlias5,	 @GlobalAttributeAlias5)
			, GlobalAttributeSource6	= IIF(@GlobalAttributeSource6	= N'<#NV>', GlobalAttributeSource6,	 @GlobalAttributeSource6)
			, GlobalAttributeAlias6		= IIF(@GlobalAttributeAlias6	= N'<#NV>', GlobalAttributeAlias6,	 @GlobalAttributeAlias6)
			, GlobalAttributeSource7	= IIF(@GlobalAttributeSource7	= N'<#NV>', GlobalAttributeSource7,	 @GlobalAttributeSource7)
			, GlobalAttributeAlias7		= IIF(@GlobalAttributeAlias7	= N'<#NV>', GlobalAttributeAlias7,	 @GlobalAttributeAlias7)
			, GlobalAttributeSource8	= IIF(@GlobalAttributeSource8	= N'<#NV>', GlobalAttributeSource8,	 @GlobalAttributeSource8)
			, GlobalAttributeAlias8		= IIF(@GlobalAttributeAlias8	= N'<#NV>', GlobalAttributeAlias8,	 @GlobalAttributeAlias8)
			, GlobalAttributeSource9	= IIF(@GlobalAttributeSource9	= N'<#NV>', GlobalAttributeSource9,	 @GlobalAttributeSource9)
			, GlobalAttributeAlias9		= IIF(@GlobalAttributeAlias9	= N'<#NV>', GlobalAttributeAlias9,	 @GlobalAttributeAlias9)
			, GlobalAttributeSource10	= IIF(@GlobalAttributeSource10	= N'<#NV>', GlobalAttributeSource10, @GlobalAttributeSource10)
			, GlobalAttributeAlias10	= IIF(@GlobalAttributeAlias10	= N'<#NV>', GlobalAttributeAlias10,	 @GlobalAttributeAlias10)
			, GlobalAttributeSource11	= IIF(@GlobalAttributeSource11	= N'<#NV>', GlobalAttributeSource11, @GlobalAttributeSource11)
			, GlobalAttributeAlias11	= IIF(@GlobalAttributeAlias11	= N'<#NV>', GlobalAttributeAlias11,	 @GlobalAttributeAlias11)			
			, GlobalAttributeSource12	= IIF(@GlobalAttributeSource12	= N'<#NV>', GlobalAttributeSource12, @GlobalAttributeSource12)
			, GlobalAttributeAlias12	= IIF(@GlobalAttributeAlias12	= N'<#NV>', GlobalAttributeAlias12,	 @GlobalAttributeAlias12)
			, GlobalAttributeSource13	= IIF(@GlobalAttributeSource13	= N'<#NV>', GlobalAttributeSource13, @GlobalAttributeSource13)
			, GlobalAttributeAlias13	= IIF(@GlobalAttributeAlias13	= N'<#NV>', GlobalAttributeAlias13,	 @GlobalAttributeAlias13)
			, GlobalAttributeSource14	= IIF(@GlobalAttributeSource14	= N'<#NV>', GlobalAttributeSource14, @GlobalAttributeSource14)
			, GlobalAttributeAlias14	= IIF(@GlobalAttributeAlias14	= N'<#NV>', GlobalAttributeAlias14,	 @GlobalAttributeAlias14)
			, GlobalAttributeSource15	= IIF(@GlobalAttributeSource15	= N'<#NV>', GlobalAttributeSource15, @GlobalAttributeSource15)
			, GlobalAttributeAlias15	= IIF(@GlobalAttributeAlias15	= N'<#NV>', GlobalAttributeAlias15,	 @GlobalAttributeAlias15)
			, GlobalAttributeSource16	= IIF(@GlobalAttributeSource16	= N'<#NV>', GlobalAttributeSource16, @GlobalAttributeSource16)
			, GlobalAttributeAlias16	= IIF(@GlobalAttributeAlias16	= N'<#NV>', GlobalAttributeAlias16,	 @GlobalAttributeAlias16)
			, GlobalAttributeSource17	= IIF(@GlobalAttributeSource17	= N'<#NV>', GlobalAttributeSource17, @GlobalAttributeSource17)
			, GlobalAttributeAlias17	= IIF(@GlobalAttributeAlias17	= N'<#NV>', GlobalAttributeAlias17,	 @GlobalAttributeAlias17)
			, GlobalAttributeSource18	= IIF(@GlobalAttributeSource18	= N'<#NV>', GlobalAttributeSource18, @GlobalAttributeSource18)
			, GlobalAttributeAlias18	= IIF(@GlobalAttributeAlias18	= N'<#NV>', GlobalAttributeAlias18,	 @GlobalAttributeAlias18)
			, GlobalAttributeSource19	= IIF(@GlobalAttributeSource19	= N'<#NV>', GlobalAttributeSource19, @GlobalAttributeSource19)
			, GlobalAttributeAlias19	= IIF(@GlobalAttributeAlias19	= N'<#NV>', GlobalAttributeAlias19,	 @GlobalAttributeAlias19)
			, GlobalAttributeSource20	= IIF(@GlobalAttributeSource20	= N'<#NV>', GlobalAttributeSource20, @GlobalAttributeSource20)
			, GlobalAttributeAlias20	= IIF(@GlobalAttributeAlias20	= N'<#NV>', GlobalAttributeAlias20,	 @GlobalAttributeAlias20)
			, GlobalAttributeSource21	= IIF(@GlobalAttributeSource21	= N'<#NV>', GlobalAttributeSource21, @GlobalAttributeSource21)
			, GlobalAttributeAlias21	= IIF(@GlobalAttributeAlias21	= N'<#NV>', GlobalAttributeAlias21,	 @GlobalAttributeAlias21)			
			, GlobalAttributeSource22	= IIF(@GlobalAttributeSource22	= N'<#NV>', GlobalAttributeSource22, @GlobalAttributeSource22)
			, GlobalAttributeAlias22	= IIF(@GlobalAttributeAlias22	= N'<#NV>', GlobalAttributeAlias22,	 @GlobalAttributeAlias22)
			, GlobalAttributeSource23	= IIF(@GlobalAttributeSource23	= N'<#NV>', GlobalAttributeSource23, @GlobalAttributeSource23)
			, GlobalAttributeAlias23	= IIF(@GlobalAttributeAlias23	= N'<#NV>', GlobalAttributeAlias23,	 @GlobalAttributeAlias23)
			, GlobalAttributeSource24	= IIF(@GlobalAttributeSource24	= N'<#NV>', GlobalAttributeSource24, @GlobalAttributeSource24)
			, GlobalAttributeAlias24	= IIF(@GlobalAttributeAlias24	= N'<#NV>', GlobalAttributeAlias24,	 @GlobalAttributeAlias24)
			, GlobalAttributeSource25	= IIF(@GlobalAttributeSource25	= N'<#NV>', GlobalAttributeSource25, @GlobalAttributeSource25)
			, GlobalAttributeAlias25	= IIF(@GlobalAttributeAlias25	= N'<#NV>', GlobalAttributeAlias25,	 @GlobalAttributeAlias25)
			, LayoutJSON				= IIF(@LayoutJSON				= N'<#NV>', LayoutJSON,				 @LayoutJSON)
		
		FROM planning.tdProductLines
		WHERE ProductLineKey = @ProductLineKey;

		SET @EffectedRows += @@ROWCOUNT;

		-- STEP 3.3 - Rights materialize (only possible for users with Factory WriteRight or Cluster Admin)
		EXEC system.spMaterialize_trUserRights;

		COMMIT TRANSACTION sx_pf_POST_ProductLine;
	END TRY
	BEGIN CATCH
		DECLARE @Error_state INT = ERROR_STATE();
		SET @Comment = ERROR_MESSAGE();

		ROLLBACK TRANSACTION sx_pf_POST_ProductLine;		

		IF @Error_state <> 10 
		BEGIN
			SET @ResultCode = 500;		
			PRINT 'Rollback due to not executable command.';
		END
		ELSE IF @ResultCode IS NULL OR @ResultCode/100 = 2
		BEGIN
			SET @ResultCode = 500;	
		END;
	END CATCH

	EXEC dbo.sx_pf_pPOST_API_LogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @EffectedRows, @ResultCode, @TimestampCall, @Comment;
	RETURN @ResultCode;
END
GO
 
ALTER AUTHORIZATION ON OBJECT ::dbo.sx_pf_POST_ProductLine TO db_octservice;
GO

-- SET documentation variables      ***********************************************************************
DECLARE
     @level0name        NVARCHAR(255)  = N'dbo'					-- enter schema name of the table
    ,@level1name        NVARCHAR(255)  = N'sx_pf_POST_ProductLine'				-- enter procedure name
    ,@SX_Owner	        NVARCHAR(255)  = N'OCT.core'						-- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom)
    ,@SX_Module			NVARCHAR(255)  = N'CORE'							-- enter module name as free text  (CORE,FIN, DEBKRED, HR, ...)
    ,@SX_ShipmentFlag	INT            = 1									-- 0 = Demo object - out of shipment process
																			
																			-- STANDARD OBJECTS
																			-- 1 = shiped from saxess standard without modification
																			-- 2 = shiped from saxess standard modified FOR customer from saxess
																			-- 3 = shiped from saxess standard modified FOR customer from partner
																			-- 4 = shiped from saxess standard modified FROM customer themself for own needs
																			-- CUSTOM OBJECTS
																			-- 10 = shiped from saxess as customer specific object
																			-- 11 = shiped from partner	as customer specific object
																			-- 12 = shiped from customer as own specific object

	,@SX_UserHint		NVARCHAR(2000) = N''								-- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage)
                                                             
 
-- KEEP this default constants      *************************************************************************
DECLARE
     @name          NVARCHAR(255)   = N'MS_Description'
    ,@level0type    NVARCHAR(255)   = N'SCHEMA'
    ,@level1type    NVARCHAR(255)   = N'PROCEDURE'
    ,@level2type    NVARCHAR(255)   = N'PARAMETER'
    ,@level2name    NVARCHAR(255)   = N''
    ,@value         NVARCHAR(1000)  = N'';
 
    SET @value = @SX_Owner;
    EXEC sys.sp_addextendedproperty N'SX_Owner'			,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_Module;
    EXEC sys.sp_addextendedproperty N'SX_Module'		,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_ShipmentFlag;
    EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag'	,@value,@level0type,@level0name,@level1type,@level1name;

	SET @value = @SX_UserHint;
    EXEC sys.sp_addextendedproperty N'SX_UserHint'		,@value,@level0type,@level0name,@level1type,@level1name;
 
 
-- SET documententation             *************************************************************************
 
 
-- SET Procedure documentation
    SET @value = N'POST Operation for ProductLine
         Not existing ProductLine will be created, existing gets an Update
         If attributes passed with value <#NV>, it will be ignored during the update and maintain the existing value, during insert the attribute is created empty';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @level2name = N'@Username';
    SET @value      = N'Username';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@ProductLineID';
    SET @value      = N'ProductLineID';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@FactoryID';
    SET @value      = N'FactoryID';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@NameShort';
    SET @value      = N'NameShort';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@NameLong';
    SET @value      = N'NameLong';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@CommentUser';
    SET @value      = N'CommentUser';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@CommentDev';
    SET @value      = N'CommentDev';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@ResponsiblePerson';
    SET @value      = N'ResponsiblePerson';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@ImageName';
    SET @value      = N'ImageName';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@DefaultTemplate';
    SET @value      = N'DefaultTemplate';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource1';
    SET @value      = N'GlobalAttributeSource1';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias1';
    SET @value      = N'GlobalAttributeAlias1';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource2';
    SET @value      = N'GlobalAttributeSource2';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias2';
    SET @value      = N'GlobalAttributeAlias2';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource3';
    SET @value      = N'GlobalAttributeSource3';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias3';
    SET @value      = N'GlobalAttributeAlias3';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource4';
    SET @value      = N'GlobalAttributeSource4';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias4';
    SET @value      = N'GlobalAttributeAlias4';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource5';
    SET @value      = N'GlobalAttributeSource5';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias5';
    SET @value      = N'GlobalAttributeAlias5';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource6';
    SET @value      = N'GlobalAttributeSource6';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias6';
    SET @value      = N'GlobalAttributeAlias6';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource7';
    SET @value      = N'GlobalAttributeSource7';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias7';
    SET @value      = N'GlobalAttributeAlias7';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource8';
    SET @value      = N'GlobalAttributeSource8';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias8';
    SET @value      = N'GlobalAttributeAlias8';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource9';
    SET @value      = N'GlobalAttributeSource9';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias9';
    SET @value      = N'GlobalAttributeAlias9';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource10';
    SET @value      = N'GlobalAttributeSource10';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias10';
    SET @value      = N'GlobalAttributeAlias10';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource11';
    SET @value      = N'GlobalAttributeSource11';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias11';
    SET @value      = N'GlobalAttributeAlias11';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource12';
    SET @value      = N'GlobalAttributeSource12';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias12';
    SET @value      = N'GlobalAttributeAlias12';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource13';
    SET @value      = N'GlobalAttributeSource13';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias13';
    SET @value      = N'GlobalAttributeAlias13';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource14';
    SET @value      = N'GlobalAttributeSource14';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias14';
    SET @value      = N'GlobalAttributeAlias14';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource15';
    SET @value      = N'GlobalAttributeSource15';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias15';
    SET @value      = N'GlobalAttributeAlias15';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource16';
    SET @value      = N'GlobalAttributeSource16';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias16';
    SET @value      = N'GlobalAttributeAlias16';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource17';
    SET @value      = N'GlobalAttributeSource17';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias17';
    SET @value      = N'GlobalAttributeAlias17';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource18';
    SET @value      = N'GlobalAttributeSource18';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias18';
    SET @value      = N'GlobalAttributeAlias18';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource19';
    SET @value      = N'GlobalAttributeSource19';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias19';
    SET @value      = N'GlobalAttributeAlias19';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource20';
    SET @value      = N'GlobalAttributeSource20';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias20';
    SET @value      = N'GlobalAttributeAlias20';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource21';
    SET @value      = N'GlobalAttributeSource21';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias21';
    SET @value      = N'GlobalAttributeAlias21';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource22';
    SET @value      = N'GlobalAttributeSource22';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias22';
    SET @value      = N'GlobalAttributeAlias22';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource23';
    SET @value      = N'GlobalAttributeSource23';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias23';
    SET @value      = N'GlobalAttributeAlias23';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource24';
    SET @value      = N'GlobalAttributeSource24';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias24';
    SET @value      = N'GlobalAttributeAlias24';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeSource25';
    SET @value      = N'GlobalAttributeSource25';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@GlobalAttributeAlias25';
    SET @value      = N'GlobalAttributeAlias25';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
GO



DROP PROCEDURE IF EXISTS import.spPOST_dProductLines;
GO

/*
	Import all values from load.tdProductLines with specific load-procedure as source

	Gerd Tautenhahn for Saxess Software GmbH
	Last modified: 10/2022 for OCT 5.8

	Testcall
		EXEC import.spPOST_dProductLines 'SQL','','','';
 
	Testcall Documentation
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'import', 'PROCEDURE', 'spPOST_dProductLines',NULL,NULL)
		UNION ALL
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'import', 'PROCEDURE', 'spPOST_dProductLines','PARAMETER',NULL)
*/
 
CREATE PROCEDURE import.spPOST_dProductLines
				(		@Username		AS NVARCHAR(255),
						@FactoryID		AS NVARCHAR(255),
						@ProductLineID	AS NVARCHAR(255),
						@Source			AS NVARCHAR(255)		  
				)
AS

BEGIN
	SET NOCOUNT ON

	-------------------------------------------------------------------------------------------------------------------
	-- ##### VARIABLES ###########
	DECLARE @TimestampCall					DATETIME		= GETUTCDATE();
	DECLARE @ProcedureName					NVARCHAR(255)	= OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
	DECLARE @ResultCode						INT				= 501;
	DECLARE @EffectedRows					INT				= 0;					
	DECLARE @TransactUsername				NVARCHAR(255)	= N'';
	DECLARE @ParameterString				NVARCHAR(MAX)	= N''''
															+ ISNULL(@Username		, N'NULL')	 + N''',''' 
															+ ISNULL(@FactoryID		, N'NULL')	 + N''','''
															+ ISNULL(@ProductLineID	, N'NULL')	 + N''','''
															+ ISNULL(@Source		, N'NULL')	 + N'''';
	DECLARE @Comment						NVARCHAR(2000)	= N'';						
	DECLARE @NameShort						NVARCHAR(255)
	DECLARE @NameLong						NVARCHAR(255)
	DECLARE @CommentUser					NVARCHAR(MAX)
	DECLARE @CommentDev						NVARCHAR(MAX)
	DECLARE @ResponsiblePerson				NVARCHAR(255)
	DECLARE @ImageName						NVARCHAR(255)
	DECLARE @DefaultTemplate				NVARCHAR(255)
	DECLARE @GlobalAttributeSource1			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias1 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource2			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias2 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource3			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias3 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource4			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias4 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource5			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias5 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource6			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias6 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource7			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias7 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource8			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias8 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource9			NVARCHAR(255)
	DECLARE @GlobalAttributeAlias9 			NVARCHAR(255)
	DECLARE @GlobalAttributeSource10		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias10			NVARCHAR(255)
	DECLARE @GlobalAttributeSource11		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias11			NVARCHAR(255)
	DECLARE @GlobalAttributeSource12		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias12			NVARCHAR(255)
	DECLARE @GlobalAttributeSource13		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias13			NVARCHAR(255)
	DECLARE @GlobalAttributeSource14		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias14			NVARCHAR(255)
	DECLARE @GlobalAttributeSource15		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias15			NVARCHAR(255)
	DECLARE @GlobalAttributeSource16		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias16			NVARCHAR(255)
	DECLARE @GlobalAttributeSource17		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias17			NVARCHAR(255)
	DECLARE @GlobalAttributeSource18		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias18			NVARCHAR(255)
	DECLARE @GlobalAttributeSource19		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias19			NVARCHAR(255)
	DECLARE @GlobalAttributeSource20		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias20			NVARCHAR(255)
	DECLARE @GlobalAttributeSource21		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias21			NVARCHAR(255)
	DECLARE @GlobalAttributeSource22		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias22			NVARCHAR(255)
	DECLARE @GlobalAttributeSource23		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias23			NVARCHAR(255)
	DECLARE @GlobalAttributeSource24		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias24			NVARCHAR(255)
	DECLARE @GlobalAttributeSource25		NVARCHAR(255)
	DECLARE @GlobalAttributeAlias25			NVARCHAR(255)
	DECLARE @LayoutJSON						NVARCHAR(MAX)

	-------------------------------------------------------------------------------------------------------------------
	-- ##### DETERMINE TRANSACTION USER ###########
	SELECT @TransactUsername = dbo.sx_pf_Determine_TransactionUsername (@Username);

	-------------------------------------------------------------------------------------------------------------------
	-- ##### TEMPORARY TABLES ###########
	IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp
	CREATE TABLE #tmp 
				(	ProductLineID			NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,FactoryID				NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,NameShort				NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,NameLong				NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,CommentUser				NVARCHAR(MAX) COlLATE DATABASE_DEFAULT NOT NULL
				   ,CommentDev				NVARCHAR(MAX) COlLATE DATABASE_DEFAULT NOT NULL
				   ,ResponsiblePerson		NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,ImageName				NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,DefaultTemplate			NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource1  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias1 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource2	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias2 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource3	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias3 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource4	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias4 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource5	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias5 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource6	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias6 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource7	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias7 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource8	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias8 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource9	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias9 	NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource10 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias10  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource11 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias11  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource12 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias12  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource13 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias13  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource14 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias14  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource15 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias15  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource16 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias16  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource17 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias17  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource18 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias18  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource19 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias19  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource20 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias20  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource21 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias21  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource22 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias22  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource23 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias23  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource24 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias24  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeSource25 NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,GlobalAttributeAlias25  NVARCHAR(255) COlLATE DATABASE_DEFAULT NOT NULL
				   ,LayoutJSON				NVARCHAR(MAX) COlLATE DATABASE_DEFAULT NOT NULL
				   )

	INSERT INTO #tmp
		SELECT   tdPL.ProductLineID			
				,tdPL.FactoryID				
				,tdPL.NameShort				
				,tdPL.NameLong				
				,tdPL.CommentUser			
				,tdPL.CommentDev			
				,tdPL.ResponsiblePerson		
				,tdPL.ImageName				
				,tdPL.DefaultTemplate		
				,tdPL.GlobalAttributeSource1
				,tdPL.GlobalAttributeAlias1 
				,tdPL.GlobalAttributeSource2
				,tdPL.GlobalAttributeAlias2 
				,tdPL.GlobalAttributeSource3
				,tdPL.GlobalAttributeAlias3 
				,tdPL.GlobalAttributeSource4
				,tdPL.GlobalAttributeAlias4 
				,tdPL.GlobalAttributeSource5
				,tdPL.GlobalAttributeAlias5 
				,tdPL.GlobalAttributeSource6
				,tdPL.GlobalAttributeAlias6 
				,tdPL.GlobalAttributeSource7
				,tdPL.GlobalAttributeAlias7 
				,tdPL.GlobalAttributeSource8
				,tdPL.GlobalAttributeAlias8 
				,tdPL.GlobalAttributeSource9
				,tdPL.GlobalAttributeAlias9 
				,tdPL.GlobalAttributeSource10
				,tdPL.GlobalAttributeAlias10 
				,tdPL.GlobalAttributeSource11
				,tdPL.GlobalAttributeAlias11 
				,tdPL.GlobalAttributeSource12
				,tdPL.GlobalAttributeAlias12 
				,tdPL.GlobalAttributeSource13
				,tdPL.GlobalAttributeAlias13 
				,tdPL.GlobalAttributeSource14
				,tdPL.GlobalAttributeAlias14 
				,tdPL.GlobalAttributeSource15
				,tdPL.GlobalAttributeAlias15 
				,tdPL.GlobalAttributeSource16
				,tdPL.GlobalAttributeAlias16 
				,tdPL.GlobalAttributeSource17
				,tdPL.GlobalAttributeAlias17 
				,tdPL.GlobalAttributeSource18
				,tdPL.GlobalAttributeAlias18 
				,tdPL.GlobalAttributeSource19
				,tdPL.GlobalAttributeAlias19 
				,tdPL.GlobalAttributeSource20
				,tdPL.GlobalAttributeAlias20 
				,tdPL.GlobalAttributeSource21
				,tdPL.GlobalAttributeAlias21 
				,tdPL.GlobalAttributeSource22
				,tdPL.GlobalAttributeAlias22 
				,tdPL.GlobalAttributeSource23
				,tdPL.GlobalAttributeAlias23 
				,tdPL.GlobalAttributeSource24
				,tdPL.GlobalAttributeAlias24 
				,tdPL.GlobalAttributeSource25
				,tdPL.GlobalAttributeAlias25  
				,tdPL.LayoutJSON
		FROM	load.tdProductLines tdPL
		WHERE	(@FactoryID = ''		OR tdPL.FactoryID = @FactoryID)
		 AND    (@ProductLineID = ''	OR tdPL.ProductLineID = @ProductLineID)
		 AND    (@Source = ''			OR tdPL.Source = @Source)
	
	-------------------------------------------------------------------------------------------------------------------
	-- ##### POST ###########
	DECLARE MyCursor CURSOR FOR
		SELECT *
		FROM #tmp t
	OPEN MyCursor
	FETCH MyCursor INTO @ProductLineID,@FactoryID,@NameShort,@NameLong,@CommentUser,@CommentDev,@ResponsiblePerson,@ImageName,@DefaultTemplate,@GlobalAttributeSource1  ,@GlobalAttributeAlias1 ,@GlobalAttributeSource2,@GlobalAttributeAlias2 ,@GlobalAttributeSource3,@GlobalAttributeAlias3 ,@GlobalAttributeSource4,@GlobalAttributeAlias4 ,@GlobalAttributeSource5,@GlobalAttributeAlias5 ,@GlobalAttributeSource6,@GlobalAttributeAlias6 ,@GlobalAttributeSource7,@GlobalAttributeAlias7 ,@GlobalAttributeSource8,@GlobalAttributeAlias8 ,@GlobalAttributeSource9,@GlobalAttributeAlias9 ,@GlobalAttributeSource10 ,@GlobalAttributeAlias10  ,@GlobalAttributeSource11 ,@GlobalAttributeAlias11  ,@GlobalAttributeSource12 ,@GlobalAttributeAlias12  ,@GlobalAttributeSource13 ,@GlobalAttributeAlias13  ,@GlobalAttributeSource14 ,@GlobalAttributeAlias14  ,@GlobalAttributeSource15 ,@GlobalAttributeAlias15  ,@GlobalAttributeSource16 ,@GlobalAttributeAlias16  ,@GlobalAttributeSource17 ,@GlobalAttributeAlias17  ,@GlobalAttributeSource18 ,@GlobalAttributeAlias18  ,@GlobalAttributeSource19 ,@GlobalAttributeAlias19  ,@GlobalAttributeSource20 ,@GlobalAttributeAlias20  ,@GlobalAttributeSource21 ,@GlobalAttributeAlias21  ,@GlobalAttributeSource22 ,@GlobalAttributeAlias22  ,@GlobalAttributeSource23 ,@GlobalAttributeAlias23  ,@GlobalAttributeSource24 ,@GlobalAttributeAlias24  ,@GlobalAttributeSource25 ,@GlobalAttributeAlias25,@LayoutJSON  
	WHILE @@FETCH_STATUS = 0
	BEGIN
		EXECUTE @ResultCode = dbo.sx_pf_POST_ProductLine
				 @Username
				,@ProductLineID				
				,@FactoryID			
				,@NameShort
				,@NameLong
				,@CommentUser
				,@CommentDev
				,@ResponsiblePerson
				,@ImageName
				,@DefaultTemplate
				,@GlobalAttributeSource1  
				,@GlobalAttributeAlias1 
				,@GlobalAttributeSource2
				,@GlobalAttributeAlias2 
				,@GlobalAttributeSource3
				,@GlobalAttributeAlias3 
				,@GlobalAttributeSource4
				,@GlobalAttributeAlias4 
				,@GlobalAttributeSource5
				,@GlobalAttributeAlias5 
				,@GlobalAttributeSource6
				,@GlobalAttributeAlias6 
				,@GlobalAttributeSource7
				,@GlobalAttributeAlias7 
				,@GlobalAttributeSource8
				,@GlobalAttributeAlias8 
				,@GlobalAttributeSource9
				,@GlobalAttributeAlias9 
				,@GlobalAttributeSource10 
				,@GlobalAttributeAlias10  
				,@GlobalAttributeSource11 
				,@GlobalAttributeAlias11  
				,@GlobalAttributeSource12 
				,@GlobalAttributeAlias12  
				,@GlobalAttributeSource13 
				,@GlobalAttributeAlias13  
				,@GlobalAttributeSource14 
				,@GlobalAttributeAlias14  
				,@GlobalAttributeSource15 
				,@GlobalAttributeAlias15  
				,@GlobalAttributeSource16 
				,@GlobalAttributeAlias16  
				,@GlobalAttributeSource17 
				,@GlobalAttributeAlias17  
				,@GlobalAttributeSource18 
				,@GlobalAttributeAlias18  
				,@GlobalAttributeSource19 
				,@GlobalAttributeAlias19  
				,@GlobalAttributeSource20 
				,@GlobalAttributeAlias20  
				,@GlobalAttributeSource21 
				,@GlobalAttributeAlias21  
				,@GlobalAttributeSource22 
				,@GlobalAttributeAlias22  
				,@GlobalAttributeSource23 
				,@GlobalAttributeAlias23  
				,@GlobalAttributeSource24 
				,@GlobalAttributeAlias24  
				,@GlobalAttributeSource25 
				,@GlobalAttributeAlias25 
				,@LayoutJSON

		PRINT @ResultCode
	FETCH MyCursor INTO  @ProductLineID,@FactoryID,@NameShort,@NameLong,@CommentUser,@CommentDev,@ResponsiblePerson,@ImageName,@DefaultTemplate,@GlobalAttributeSource1  ,@GlobalAttributeAlias1 ,@GlobalAttributeSource2,@GlobalAttributeAlias2 ,@GlobalAttributeSource3,@GlobalAttributeAlias3 ,@GlobalAttributeSource4,@GlobalAttributeAlias4 ,@GlobalAttributeSource5,@GlobalAttributeAlias5 ,@GlobalAttributeSource6,@GlobalAttributeAlias6 ,@GlobalAttributeSource7,@GlobalAttributeAlias7 ,@GlobalAttributeSource8,@GlobalAttributeAlias8 ,@GlobalAttributeSource9,@GlobalAttributeAlias9 ,@GlobalAttributeSource10 ,@GlobalAttributeAlias10  ,@GlobalAttributeSource11 ,@GlobalAttributeAlias11  ,@GlobalAttributeSource12 ,@GlobalAttributeAlias12  ,@GlobalAttributeSource13 ,@GlobalAttributeAlias13  ,@GlobalAttributeSource14 ,@GlobalAttributeAlias14  ,@GlobalAttributeSource15 ,@GlobalAttributeAlias15  ,@GlobalAttributeSource16 ,@GlobalAttributeAlias16  ,@GlobalAttributeSource17 ,@GlobalAttributeAlias17  ,@GlobalAttributeSource18 ,@GlobalAttributeAlias18  ,@GlobalAttributeSource19 ,@GlobalAttributeAlias19  ,@GlobalAttributeSource20 ,@GlobalAttributeAlias20  ,@GlobalAttributeSource21 ,@GlobalAttributeAlias21  ,@GlobalAttributeSource22 ,@GlobalAttributeAlias22  ,@GlobalAttributeSource23 ,@GlobalAttributeAlias23  ,@GlobalAttributeSource24 ,@GlobalAttributeAlias24  ,@GlobalAttributeSource25 ,@GlobalAttributeAlias25 ,@LayoutJSON
	END
	CLOSE MyCursor
	DEALLOCATE MyCursor

	SET @ResultCode = 200;

	EXEC dbo.sx_pf_pPOST_API_LogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @EffectedRows, @ResultCode, @TimestampCall, @Comment;

	RETURN @ResultCode;

END;

-------------------------------------------------------------------------------------------------------------------
GO

-- SET documentation variables      ***********************************************************************
DECLARE
     @level0name        NVARCHAR(255)  = N'import'					-- enter schema name of the table
    ,@level1name        NVARCHAR(255)  = N'spPOST_dProductLines'				-- enter procedure name
    ,@SX_Owner	        NVARCHAR(255)  = N'OCT.core'						-- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom)
    ,@SX_Module			NVARCHAR(255)  = N'CORE'							-- enter module name as free text  (CORE,FIN, DEBKRED, HR, ...)
    ,@SX_ShipmentFlag	INT            = 1									-- 0 = Demo object - out of shipment process
																			
																			-- STANDARD OBJECTS
																			-- 1 = shiped from saxess standard without modification
																			-- 2 = shiped from saxess standard modified FOR customer from saxess
																			-- 3 = shiped from saxess standard modified FOR customer from partner
																			-- 4 = shiped from saxess standard modified FROM customer themself for own needs
																			-- CUSTOM OBJECTS
																			-- 10 = shiped from saxess as customer specific object
																			-- 11 = shiped from partner	as customer specific object
																			-- 12 = shiped from customer as own specific object

	,@SX_UserHint		NVARCHAR(2000) = N''								-- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage)
                                                             
 
-- KEEP this default constants      *************************************************************************
DECLARE
     @name          NVARCHAR(255)   = N'MS_Description'
    ,@level0type    NVARCHAR(255)   = N'SCHEMA'
    ,@level1type    NVARCHAR(255)   = N'PROCEDURE'
    ,@level2type    NVARCHAR(255)   = N'PARAMETER'
    ,@level2name    NVARCHAR(255)   = N''
    ,@value         NVARCHAR(1000)  = N'';
 
    SET @value = @SX_Owner;
    EXEC sys.sp_addextendedproperty N'SX_Owner'			,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_Module;
    EXEC sys.sp_addextendedproperty N'SX_Module'		,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_ShipmentFlag;
    EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag'	,@value,@level0type,@level0name,@level1type,@level1name;

	SET @value = @SX_UserHint;
    EXEC sys.sp_addextendedproperty N'SX_UserHint'		,@value,@level0type,@level0name,@level1type,@level1name;
 
 
-- SET documententation             *************************************************************************
 
 
-- SET Procedure documentation
    SET @value = N'Import all values from load.tdProductLines with specific load-procedure as source';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @level2name = N'@Username';
    SET @value      = N'Username';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@FactoryID';
    SET @value      = N'FactoryID';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@ProductLineID';
    SET @value      = N'ProductLineID';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
    SET @level2name = N'@Source';
    SET @value      = N'Source';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name,@level2type,@level2name;
 
GO


DROP PROCEDURE IF EXISTS system.spGET_ConnectorTree;
GO

/*
	Toni August for Saxess Software GmbH
	Last modified: 12/2022 for OCT 5.9
 
	Testcall Procedure
		DECLARE  @RC INT;
		EXEC	 @RC = system.spGET_ConnectorTree
				 @Username		= 'SQL'
		PRINT    @RC

	Testcall Documentation
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'system', 'PROCEDURE', 'spGET_ConnectorTree',NULL,NULL)
		UNION ALL
		SELECT * FROM ::fn_listextendedproperty (NULL, 'SCHEMA', 'system', 'PROCEDURE', 'spGET_ConnectorTree','PARAMETER',NULL)
*/
 
CREATE PROCEDURE system.spGET_ConnectorTree
    (
         @Username				NVARCHAR(255)
    )

AS 
	BEGIN	
		-- Standard declaration for logging
		DECLARE 
				 @ProcedureName		NVARCHAR(255)	= OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID)

				-- SET PARAMETER LOG STRING -inside in single quotes (N''','''), Numbers without strings inside without quotes (N','), end list with '''' in case of string or '' in case of number on last position
				,@ParameterString	NVARCHAR(MAX)	= N''''					
				+ ISNULL(@Username					,N'NULL')	+ N''''

				,@EffectedRows		INT				= 0			
				,@ResultCode		INT				= 501				
				,@TimestampCall		DATETIME		= GETUTCDATE()
				,@Comment			NVARCHAR(2000)	= N''
				,@TransactUsername	NVARCHAR(255)	= N''
				,@StartTime			DATETIME2		= SysUTCDateTime();


		-- NULL Protection for all Input parameters
		IF @Username				IS NULL SET @Username			= N'';

		BEGIN TRY
			-- check transaction user existence
			SELECT @TransactUsername = dbo.sx_pf_Determine_TransactionUsername (@Username);
				IF @TransactUsername  = N'403' 
				BEGIN
					SET @ResultCode = 403;
					RAISERROR('Transaction user doesn''t exist', 16, 10);
				END;

			-- Temp table to store all integration tables of all modules
			DROP TABLE IF EXISTS #ModuleTables;

			SELECT
				SUBSTRING(t.name, 2, CHARINDEX('_', t.name) - 2) COLLATE DATABASE_DEFAULT AS ModuleID,
				SUBSTRING(t.name, CHARINDEX('_', t.name) + 1, 255) COLLATE DATABASE_DEFAULT AS IntegrationTable
			INTO #ModuleTables
			FROM sys.tables t
			JOIN sys.schemas s ON s.schema_id = t.schema_id
			WHERE s.name = 'integration'
			AND t.name LIKE 't%[_]%';

			-- Add GetCompanies to all modules as default
			INSERT INTO #ModuleTables
			SELECT DISTINCT
				ModuleID,
				'GetCompanies'
			FROM #ModuleTables;
				
			-- Data output
			SELECT
				SourceSystemID,
				SourceSystemType,
				ModuleID,
				ConnectorDescription,
				ConnectorShortDescription,
				ConnectorVersion,
				QueryName,
				Manufacturer
			FROM (
				SELECT
					c.SourceSystemID,
					c.SourceSystemType,
					c.ModuleID,
					c.ConnectorDescription,
					c.ConnectorShortDescription,
					c.ConnectorVersion,
					mt.IntegrationTable AS QueryName,
					CASE WHEN mt.IntegrationTable = 'GetCompanies' THEN 0 ELSE 1 END IsGetCompanies,
					c.Manufacturer
				FROM system.tConnectors AS c
				CROSS APPLY #ModuleTables AS mt
				LEFT JOIN system.tConnectorQueries AS ct
				ON ct.ConnectorKey = c.ConnectorKey
				AND ct.QueryName = mt.IntegrationTable
				WHERE c.ModuleID = mt.ModuleID

				UNION
			
				SELECT
					c.SourceSystemID,
					c.SourceSystemType,
					c.ModuleID,
					c.ConnectorDescription,
					c.ConnectorShortDescription,
					c.ConnectorVersion,
					CASE WHEN ct.ConnectorKey IS NULL THEN 'GetCompanies' ELSE ct.QueryName END AS QueryName,
					CASE WHEN ct.QueryName = 'GetCompanies' THEN 0 ELSE 1 END IsGetCompanies,
					c.Manufacturer
				FROM system.tConnectors AS c
				LEFT JOIN system.tConnectorQueries AS ct
				ON ct.ConnectorKey = c.ConnectorKey
				AND ct.ConnectorKey IS NOT NULL
			) Queries
			ORDER BY SourceSystemID, ModuleID, SourceSystemType, IsGetCompanies, QueryName;

			SET @EffectedRows = @@ROWCOUNT;
			SET @ResultCode = 200;
		END TRY

		-- START CATCH				***********************************************************************************
		BEGIN CATCH
			DECLARE @Error_state INT = ERROR_STATE();
			SET @Comment = ERROR_MESSAGE();
			
			IF @Error_state <> 10 
			BEGIN
				SET @ResultCode = 500;		
				PRINT 'Rollback due to not executable command.';
			END
			ELSE IF @ResultCode IS NULL OR @ResultCode/100 = 2
			BEGIN
				SET @ResultCode = 500;	
			END;
		END CATCH

		EXEC dbo.sx_pf_pPOST_API_LogEntry @Username, @TransactUsername, @ProcedureName, @ParameterString, @EffectedRows, @ResultCode, @TimestampCall, @Comment;
		RETURN @ResultCode;
	END
GO

-- SET documentation variables      ***********************************************************************
DECLARE
     @level0name        NVARCHAR(255)   = N'system'    -- enter schema name of the table
    ,@level1name        NVARCHAR(255)   = N'spGET_ConnectorTree'         -- enter procedure name
    ,@SX_Owner	        NVARCHAR(255)   = N'OCT.core'       -- enter owner name of the procedure from list (OCT.core, OCT.modules, Custom)
    ,@SX_Module			NVARCHAR(255)   = N'CORE'           -- enter module name as free text  (CORE,FIN, DEBKRED, HR, ...)
    ,@SX_ShipmentFlag	INT             = 1					-- 0 = Demo object - out of shipment process
                                                            -- STANDARD OBJECTS
                                                            -- 1 = shiped from saxess standard without modification
                                                            -- 2 = shiped from saxess standard modified FOR customer from saxess
                                                            -- 3 = shiped from saxess standard modified FOR customer from partner
                                                            -- 4 = shiped from saxess standard modified FROM customer themself for own needs
															-- CUSTOM OBJECTS
                                                            -- 10 = shiped from saxess as customer specific object
															-- 11 = shiped from partner	as customer specific object
															-- 12 = shiped from customer as own specific object

	,@SX_UserHint		NVARCHAR(2000) = N''				-- optional, fill if Procedure shall be offerend for end user (e.g. for Pivot / Datagrid usage)
                                                             
-- KEEP this default constants      *************************************************************************
DECLARE
     @name          NVARCHAR(255)   = N'MS_Description'
    ,@level0type    NVARCHAR(255)   = N'SCHEMA'
    ,@level1type    NVARCHAR(255)   = N'PROCEDURE'
    ,@level2type    NVARCHAR(255)   = N'PARAMETER'
    ,@level2name    NVARCHAR(255)   = N''
    ,@value         NVARCHAR(1000)  = N'';
 
    SET @value = @SX_Owner;
    EXEC sys.sp_addextendedproperty N'SX_Owner'			,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_Module;
    EXEC sys.sp_addextendedproperty N'SX_Module'		,@value,@level0type,@level0name,@level1type,@level1name;
 
    SET @value = @SX_ShipmentFlag;
    EXEC sys.sp_addextendedproperty N'SX_ShipmentFlag'	,@value,@level0type,@level0name,@level1type,@level1name;

	SET @value = @SX_UserHint;
    EXEC sys.sp_addextendedproperty N'SX_UserHint'		,@value,@level0type,@level0name,@level1type,@level1name;
 
-- SET documententation             *************************************************************************
 
-- SET Procedure documentation
    SET @value = N'Procedure to get one or all Connectors.';
    EXEC sys.sp_addextendedproperty @name,@value,@level0type,@level0name,@level1type,@level1name;
 

	GO


UPDATE system.tSettings SET ValueText = '5.11.18', ValueInt = 51118 WHERE SettingID = 'DBVersion'

