我在 SQL Server 中有这个存储过程:
alter PROCEDURE [dbo].[spSendLogLinesAsXML]
(
@device_id varchar(128),
@application_name VARCHAR(64),
@application_user_name VARCHAR(6),
@log_lines_xml XML
)
AS
BEGIN
DECLARE
@ixml INT,
@log_line_dt DATETIME,
@log_line_message varchar(max)
EXEC sp_xml_preparedocument @ixml OUTPUT,
@log_lines_xml
SELECT @log_line_dt = dt,
@log_line_message = data
FROM OPENXML(@ixml, '/lines/line', 3) WITH (
dt DATETIME,
data varchar(max)
)
--I want to do the following for each line element
EXEC spSendLogLine
@device_id = @device_id,
@application_name = @application_name,
@application_user_name = @application_user_name,
@log_line_dt = @log_line_dt,
@log_line_message = @log_line_message
EXEC sp_xml_removedocument @ixml
return -100
END
我这样调用存储过程:
EXEC @return_value = [dbo].[spSendLogLinesAsXML]
@device_id = N'devid123',
@application_name = N'CJA App 1',
@application_user_name = N'anatoli',
@log_lines_xml = '<lines><line><dt>2013-03-01T13:00:00</dt><data>Something happened and it was logged</data></line><line><dt>2013-03-01T13:01:00</dt><data>Oh my god the building is burning and people are dying</data></line></lines>'
如何修改我的存储过程以为每个行元素调用 spSendLogLine?
编辑:根据SQL - 每个记录游标的调用存储过程都是坏的。所以我想知道一个更好的方法。我不介意我的存储过程为了实现这一点而改变了多少,只要它最终能正常工作并且很好。