90 lines
4.1 KiB
Transact-SQL
90 lines
4.1 KiB
Transact-SQL
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_DBImportMMEMainLocations]') AND type in (N'P', N'PC'))
|
||
DROP PROCEDURE [dbo].[sp_DBImportMMEMainLocations]
|
||
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_DBImportMMEMainLocations]') AND type in (N'P', N'PC'))
|
||
BEGIN
|
||
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_DBImportMMEMainLocations] AS'
|
||
END
|
||
GO
|
||
ALTER PROCEDURE [dbo].[sp_DBImportMMEMainLocations]
|
||
@MMEMainLocations xml
|
||
,@errorNumber int output
|
||
,@errorMessage nvarchar(250) output
|
||
AS
|
||
BEGIN
|
||
|
||
|
||
begin try
|
||
begin transaction tMMEMainLocations
|
||
insert into [dbo].[MMEMainLocations]
|
||
([s_GUID]
|
||
,[TYPE]
|
||
,[TRANS_MAIN_LOC]
|
||
,[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('(./TYPE)[1]', 'nvarchar(50)')
|
||
,t.x.value('(./TRANS_MAIN_LOC)[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 @MMEMainLocations.nodes('/CustomMainLocs/TransducerMainLocation') t(x)
|
||
OPTION (OPTIMIZE FOR ( @MMEMainLocations = NULL ))
|
||
|
||
commit transaction tMMEMainLocations
|
||
end try
|
||
begin catch
|
||
set @errorNumber = error_number()
|
||
set @errorMessage = error_message()
|
||
rollback transaction tMMEMainLocations
|
||
end catch;
|
||
END
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
GO
|