开发者

How do we know how many columns come from XML variable in SQL Server 2005

开发者 https://www.devze.com 2023-01-27 17:41 出处:网络
I am passing XML type variable from one procedure to another procedure. Set XML variable like this Declare @XMLDOC XML

I am passing XML type variable from one procedure to another procedure.

Set XML variable like this

Declare @XMLDOC XML

set @XMLDOC = (select 60 as RecordDetailID,            
                      '' as ItemText,            
                      '' as ItemNote,            
                      0 as DisplayOrder                        
               FOR XML RAW) 

In some case I need send one more "Status" column to another procedure like below

  set @XMLDOC = (select  60 as RecordDetailID,            
                         '' as ItemText,            
                         '' as ItemNote,            
                         0 as DisplayOrder,
                         1 as Status  
                 FOR XML RAW) 

How I would know how many 开发者_运维知识库columns have been sent to my the XML Type variable?


You can use the nodes() method to count XML attributes:

select count(1) from @XMLDOC.nodes('row/@*') as T(c);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号