Files
DP44/DataPRO_sql/dbo.sp_DBImportMMEPositions.StoredProcedure.sql

88 lines
3.8 KiB
MySQL
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
<EFBFBD><EFBFBD>IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_DBImportMMEPositions]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_DBImportMMEPositions]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_DBImportMMEPositions]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_DBImportMMEPositions] AS'
END
GO
ALTER PROCEDURE [dbo].[sp_DBImportMMEPositions]
@MMEPositions xml
,@errorNumber int output
,@errorMessage nvarchar(250) output
AS
BEGIN
begin try
begin transaction tMMEPositions
insert into [dbo].[MMEPositions]
([s_GUID]
,[POSITION]
,[TEXT_L1]
,[TEXT_L2]
,[VERSION]
,[DATE]
,[REMARKS]
,[EXPIRED]
,[SORTKEY]
,[LAST_CHANGE]
,[LAST_CHANGE_TEXT]
,[HISTORY])
select
t.x.value('(./s_GUID)[1]', 'nvarchar(50)')
,t.x.value('(./POSITION)[1]', 'nvarchar(50)')
,t.x.value('(./TEXT_L1)[1]', 'nvarchar(50)')
,t.x.value('(./TEXT_L2)[1]', 'nvarchar(50)')
,t.x.value('(./VERSION)[1]', 'int')
,t.x.value('(./DATE)[1]', 'datetime')
,t.x.value('(./REMARKS)[1]', 'nvarchar(50)')
,t.x.value('(./EXPIRED)[1]', 'bit')
,t.x.value('(./SORTKEY)[1]', 'nvarchar(50)')
,t.x.value('(./LAST_CHANGE)[1]', 'datetime')
,t.x.value('(./LAST_CHANGE_TEXT)[1]', 'nvarchar(50)')
,t.x.value('(./HISTORY)[1]', 'nvarchar(50)')
from @MMEPositions.nodes('/CustomPositions/Position') t(x)
OPTION (OPTIMIZE FOR ( @MMEPositions = NULL ))
commit transaction tMMEPositions
end try
begin catch
set @errorNumber = error_number()
set @errorMessage = error_message()
rollback transaction tMMEPositions
end catch;
END
GO