Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete specific node from XML column


Delete specific node from XML column

Author
Message
thbaig
thbaig
SSC-Enthusiastic
SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)

Group: General Forum Members
Points: 136 Visits: 475
TABLE tblProduct
ProductId int
Productname varchar(20)

TABLE tblQuantityP
QuantityPId
Quantity int
Price int
ProductId XML

DATA IN tblProduct
ProductId ProductName
1         Prod1
2         Prod2
3         Prod3   
4         Prod4
5         Prod5
6         Prod6

DATA IN tblQuantityP
QuantityPId Quantity   Price   ProductId   
1            12      12      <itemids> <itemid>1</itemid> <itemid>2</itemid> <itemid>3</itemid></itemids>
2            11      21      <itemids> <itemid>2</itemid> <itemid>5</itemid> <itemid>6</itemid></itemids>
3            11      11      <itemids> <itemid>222</itemid> <itemid>5</itemid> <itemid>6</itemid></itemids>
4            134      11      <itemids> <itemid>2</itemid> <itemid>5</itemid> <itemid>6</itemid></itemids>
5            112      11      <itemids> <itemid>2</itemid> <itemid>5</itemid> <itemid>6</itemid></itemids>

Now I can JOIN XML COLUMN TO mother TABLE TO GET DATA AS following . (suggest IF SOME more optimized way: Not real question)
SELECT qp.QuantityPId ,
Prod.ProductId ,
Prod.ProductName
FROM dbo.tblQuantityP qp
CROSS APPLY ProductId.nodes('itemids/itemid') AS xmlitems ( itemid )
JOIN dbo.tblProduct Prod ON Prod.ProductId = xmlitems.ProductId.value('.',
'int');

My Question is can I DELETE DATA FROM tblQuantityP.ProductId in a way IF parent TABLE has NOT record against it ?
e.g. Prod1 with ProductId 1 removed from tblProduct, can I DELETE ONly ProductId 1 FROM ALL occurance IN tblQuantityP.ProductId?
Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2924 Visits: 4076
thbaig1 (1/23/2013)
can I DELETE DATA FROM tblQuantityP.ProductId in a way IF parent TABLE has NOT record against it ?
e.g. Prod1 with ProductId 1 removed from tblProduct, can I DELETE ONly ProductId 1 FROM ALL occurance IN tblQuantityP.ProductId?


Something like this ?

delete p from tblQuantityP Where exists (select 2 from tblProduct t where t.ProductId = p.ProductId and p.ProductId = 1)



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search