判断存储过程是否存在,存在这Drop
IF (SELECT COUNT(*) FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[StoreProcedureName]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) > 0
BEGIN
DROP PROCEDURE [dbo].[StoreProcedureName];
END;
GO
创建存储过程
CREATE PROCEDURE [dbo].[PFSA_PANA_TRACE_DATA_INS_XML] (@xml XML)
AS
BEGIN
END;
GO
变量
--创建变量
DECLARE @Lot_No INT
DECLARE @Work_Date varchar(20)
-- 直接赋值
set @Lot_No = 000
set @Work_Date = "ABC"
XML解析以及使用
CREATE PROCEDURE [dbo].[StoreProcedureName] (@xml XML)
AS
BEGIN
-- 单个变量从XML获取赋值
DECLARE @Work_Date varchar(20)
select @Work_Date = @xml.value('(/RowList/Row/@z_cass_startTime)[1]','varchar(50)')
-- 通过Insert 直接从XML获取数据插入
--Declare internal Variables
DECLARE @handle INT
--Create XML Document
EXEC sp_xml_preparedocument @handle OUTPUT, @xml
-- 按照顺序写入,并非按照LineName的名称写入Table中
INSERT INTO PFSA_PANA_MV_DATA
SELECT *
FROM OPENXML(@handle, N'/RowList/Row') WITH (LineNum int '@LINENUM',
LineName nvarchar(20) '@LINENAME',
ZoneNum int '@ZONENUM',
ZoneName nvarchar(40) '@ZONENAME'
)
EXEC sp_xml_removedocument @handle
-- 通过XML获取值,插入到临时表中
Select
col.value('@cellId[1]' , 'varchar(50)') AS Lot_No,
col.value('@cellId[1]' , 'varchar(50)') as Work_Date
INTO #tempScarpData
from @xml.nodes('/RowList/Row') as ref(col)
END
GO