Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 XML and scope identity

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-26 : 16:45:34
OK, So I'm Getting some XML Like this


<PifToMepData Mode=\"3\">
<MEP MEPName=\"Test Combining PIFs\" MEPType=\"Close\" PIFRecId=\"12\" IsPrimaryPIF=\"1\"><AssignedTo>X000525</AssignedTo></MEP>
<MEP MEPName=\"Test Combining PIFs\" MEPType=\"Close\" PIFRecId=\"13\" IsPrimaryPIF=\"0\"><AssignedTo>X000525</AssignedTo></MEP>
</PifToMepData>


I then use


INSERT INTO #myTemp99 (
Mode
, MEPName
, MEPType
, PIFRecId
, IsPrimaryPIF
, AssignedTo)
SELECT *
FROM OPENXML (@idoc, './/AssignedTo',3)
WITH(
Mode varchar(20) '../../@Mode'
,MEPName varchar(2000) '../@MEPName'
,MEPType varchar(500) '../@MEPType'
,PIFRecId int '../@PIFRecId'
,IsPrimaryPIF varchar(20) '../@IsPrimaryPIF'
,AssignedTo varchar(20) '.'
)


To Parse it out. This then has to be inserted into another table with an identity column (damn Identity column), and I need to grab the generated id for each row, because then there are other children tables that need to be populated.

Question: Is there any set way to grab multiple generated id's?
Or do I need to loop or use a cursor?

Is the 1% of the time that they are needed?

Any ideas?
Here's the temp table DDL


CREATE TABLE #myTemp99 (
Mode varchar(20)
, MEPName varchar(2000)
, MEPType varchar(500)
, PIFRecId int
, IsPrimaryPIF varchar(20)
, AssignedTo varchar(20))


And the document prep
DECALRE @idoc varchar(8000)
--Just assign the sampel data
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

EXEC sp_xml_removedocument @idoc

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-26 : 16:53:21
you're on 2000? bummer.... in 2k5 you can do this...

i guesss you could first select the Max id, import xml and then do
select id from MyTable where Id > @yourPreviousMaxId


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-26 : 17:01:12
quote:
Originally posted by spirit1

you're on 2000? bummer.... in 2k5 you can do this...

i guesss you could first select the Max id, import xml and then do
select id from MyTable where Id > @yourPreviousMaxId


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com



Really? How do you do it in 2k5?

In any case the other idea is a bit dicey don't you think?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-26 : 17:05:05
by using the output clause:
http://weblogs.sqlteam.com/mladenp/archive/2006/06/08/10122.aspx

dicey? why?
well i don't really know how much concurrency this needs...

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-29 : 12:28:13
yeah but someone can grab that before you do the insert


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-29 : 12:34:26
well... if you only do access to this from one sproc you could use application locks...
look up sp_getapplock

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-11-29 : 12:57:42
but that's gotta be worse than a cursor

thanks though



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-29 : 13:00:34
acctually it's not.
works pretty ok

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -