[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How Do I Query XML In SQL 2005?

Posted on 2008-06-15
6
Medium Priority
?
1,149 Views
Last Modified: 2011-10-19
Attached is the SQL that I have to turn an XML column into relational data.  I've read that using OPENXML is very intensive and that SQL 2005 has a new method to do this.  I need to accomplish 2 other additional things.  The first is that I need to be able to filter off of the first Node.  So in the example below I want to pass in the BatchKey value and only have the record with that BatchKey returned.  Also, I would like to pass in path to search.  In the example below it is DocumentElement/GMAUpload.  I would like to pass in other values other than GMAUpload to allow me to only have 1 SP for this application.

I am looking for help converting this to the most efficient XML method as well as the 2 filters.  Can anyone help?
DECLARE @idoc int
DECLARE @xmlDocument xml
 
SELECT	@xmlDocument = Data
FROM	dbo.AS400UploadData
 
EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlDocument
 
SELECT	*
FROM	OPENXML (@idoc, 'DocumentElement/GMAUpload',3)
		WITH (	BatchKey varchar(50)
,			CompanyNo  varchar(5)
,			ProjectNo varchar(3)
,			BudgetTypeVer varchar(3)
,			BudgetLedgerType varchar(2)
,			FromMonth int
,			FromYear int
,			ToMonth int
,			ToYear int
,			ObjectAcct varchar(6)
,			[Description] varchar(20)
,			PlanNo varchar(2)
,			Units int
,			Amount int
,			SequenceNo int
,			ExcelRow	int	)

Open in new window

0
Comment
Question by:agorsky73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21789154
You need to provide some sample XML that you have so I can parse it for you....
0
 

Author Comment

by:agorsky73
ID: 21789290
I have attached a sample.  This data is exported from a .NET Data Table.
XMLSample.txt
0
 

Author Comment

by:agorsky73
ID: 21789299
I forgot to add the reminder that this data is retrieved from a SQL Table.  You will see on line 4 & 5 where I extract the XML and put it into a variable.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 60

Accepted Solution

by:
chapmandew earned 2000 total points
ID: 21789344
I am not sure I understand the 2nd part of your question, but this will take care of the 1st part for 2005 XML data:
declare @x xml
set @x = '<DocumentElement>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00100</Company>
    <Project>111</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00101</Company>
    <Project>112</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00102</Company>
    <Project>113</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00103</Company>
    <Project>114</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00104</Company>
    <Project>115</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00105</Company>
    <Project>116</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00106</Company>
    <Project>117</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00107</Company>
    <Project>118</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00108</Company>
    <Project>119</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00109</Company>
    <Project>120</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00110</Company>
    <Project>121</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00111</Company>
    <Project>122</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00112</Company>
    <Project>123</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00113</Company>
    <Project>124</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00114</Company>
    <Project>125</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00115</Company>
    <Project>126</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00116</Company>
    <Project>127</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00117</Company>
    <Project>128</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00118</Company>
    <Project>129</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00119</Company>
    <Project>130</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00120</Company>
    <Project>131</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00121</Company>
    <Project>132</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00122</Company>
    <Project>133</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00123</Company>
    <Project>134</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00124</Company>
    <Project>135</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00125</Company>
    <Project>136</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00126</Company>
    <Project>137</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00127</Company>
    <Project>138</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00128</Company>
    <Project>139</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00129</Company>
    <Project>140</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00130</Company>
    <Project>141</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00131</Company>
    <Project>142</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00132</Company>
    <Project>143</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00133</Company>
    <Project>144</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00134</Company>
    <Project>145</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00135</Company>
    <Project>146</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00136</Company>
    <Project>147</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00137</Company>
    <Project>148</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00138</Company>
    <Project>149</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>1</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>2</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Test Desc</Description>
    <Plan>1A</Plan>
    <Units>5</Units>
    <Amount>5000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
  <GMAUpload>
    <BatchKey>agorsky15608112859888</BatchKey>
    <Company>00139</Company>
    <Project>150</Project>
    <VersionType>001</VersionType>
    <LedgerType>BA</LedgerType>
    <FromMonth>3</FromMonth>
    <FromYear>7</FromYear>
    <ToMonth>4</ToMonth>
    <ToYear>7</ToYear>
    <ObjectAcct>OA1234</ObjectAcct>
    <Description>Another Test</Description>
    <Plan>2B</Plan>
    <Units>10</Units>
    <Amount>7000</Amount>
    <Sequence>1</Sequence>
    <Row>0</Row>
  </GMAUpload>
</DocumentElement>'
 
select 
	t.c.query('./BatchKey').value('.', 'varchar(200)'), 
    t.c.query('./Company').value('.', 'varchar(200)'), 
    t.c.query('./Project').value('.', 'varchar(200)'), 
    t.c.query('./VersionType').value('.', 'varchar(200)'), 
    t.c.query('./LedgerType').value('.', 'varchar(200)'), 
    t.c.query('./FromMonth').value('.', 'varchar(200)'), 
    t.c.query('./FromYear').value('.', 'varchar(200)'), 
    t.c.query('./ToMonth').value('.', 'varchar(200)'), 
    t.c.query('./ToYear').value('.', 'varchar(200)'), 
    t.c.query('./ObjectAcct').value('.', 'varchar(200)'), 
    t.c.query('./Description').value('.', 'varchar(200)'), 
    t.c.query('./Plan').value('.', 'varchar(200)'), 
    t.c.query('./Units').value('.', 'varchar(200)'), 
    t.c.query('./Amount').value('.', 'varchar(200)'), 
    t.c.query('./Sequence').value('.', 'varchar(200)'), 
    t.c.query('./Row').value('.', 'varchar(200)')
from @x.nodes('/DocumentElement/GMAUpload') t(c)
where t.c.query('./BatchKey').value('.', 'varchar(200)') = 'agorsky15608112859888'

Open in new window

0
 

Author Comment

by:agorsky73
ID: 21789430
Thank you very much. My second question is not an issue anylonger.
0
 

Author Closing Comment

by:agorsky73
ID: 31467367
Thank you for the quick and detailed answer!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question