Hi, I'm not sure of the soundness of the following architecture, but right now, the following information is for a prototype at this time.
I have a stored procedure that currently lets me:
- Pass an owner memberID and say an ID for a new event record
- In the member table, I have an XML field say called events, and the new event ID gets added as a new node to that XML field
All works fine, and it then makes it easy to retrieve the event ID's for that member (actually it does a join to the actual event table, and retrieves the req. data).
I now need to:
a) Instead of passing just the owner member ID, need to pass say a collection of member ID's to add that new event ID to..
The other option of course is to get the member ID's separately, and loop through within say c# code and call the proc x times.. doesn't seem a good idea...
Any thoughts? I have included the existing proc below which deals with an individual member ID.
CREATE PROCEDURE [dbo].[put_addEventIDmemberXML]
@memberID bigint = null,
@addNodeID varchar(255) = null
AS
BEGIN
SET NOCOUNT ON;
/* Get our XML nodes for the owner ID */
DECLARE @x XML
DECLARE @newIDnodeXML XML
SET @newIDnodeXML = '<id>' + @addNodeID + '</id>'
set @x = (select memberEvents from members where memberID = @memberID)
/* Check if the new node ID exists within our member XML nodes */
IF NOT EXISTS (
SELECT * FROM @x.nodes('/root/id') n(x) WHERE x.value('.','bigint') = @addNodeID
)
begin
SET @x.modify('insert sql:variable("@newIDnodeXML") as last into /root[1]')
UPDATE dbo.members
SET memberEvents = @x
WHERE memberID = @memberID
end
END