I asked this previously around 6 weeks ago but I wasn't particularly clear in terms of what I posted, what I expected and how it could be achieved. Despite the patience of some users, I was unable to solve my issue. I've gone back and tried to learn a bit more and hopefully I can now post something that makes more sense.
A customer sends his delivery schedules in the format of an XML file. It's not the most eloquent of files but I think I've made sense of it. What I need to get from it is a table like this, that tells me what quantity the customer wants of any given part on any given week. There's 50+ parts and 12 weeks but I've reduced it to 5 in the hope it can be posted here ok.
Schedule Date PartNumber Week Number Quantity
20/02/2020 Part0 0 0
20/02/2020 Part0 1 50
20/02/2020 Part0 2 0
20/02/2020 Part0 3 0
20/02/2020 Part0 4 50
20/02/2020 Part0 5 0
20/02/2020 Part1 0 0
20/02/2020 Part1 1 40
What I'll be doing is appending this information to a table every week and the schedule date is the date of the schedule. This date is taken from this line (line 11):
<Field Name="DataDate2" FieldName="DataDate"><FormattedValue>10/02/2020</FormattedValue><Value>2020-02-10</Value></Field>
The part number, Week Number & Quantity are slightly more complicated. The part number comes from a list of numbers
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">PART0</RowTotal>
<RowTotal RowNumber="1">PART1</RowTotal>
<RowTotal RowNumber="2">PART2</RowTotal>
<RowTotal RowNumber="3">PART3</RowTotal>
<RowTotal RowNumber="4">PART4</RowTotal>
<RowTotal RowNumber="5">PART5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
and the week number & quantity from this section;
<Cells>
<Cell RowNumber="0" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
where the row number is the part number reference and the column number the week. The value is the value (and formatted value).
What I was thinking was creating two tables, a reference table with all the part numbers & row numbers and a second table with the row number, week number and quantity, then join them together on the row field. Either of the tables can hold the Schedule Date.
Could someone please give me some code to help me achieve this.
I've tried this as a starting point to create the first table of part numbers but this just returns 0 records:
DECLARE @xml XML
SELECT @xml =
CONVERT(XML,bulkcolumn,2) FROM OPENROWSET(BULK 'theFile.xml',SINGLE_BLOB) AS X
DECLARE @tempTable TABLE (
partnumber NVARCHAR(50),
rownumber int
)
INSERT INTO @tempTable
SELECT Tbl.Col.value('@RowNumber', 'INT'),
Tbl.Col.value('@RowTotal','NVARCHAR(50)')
FROM @xml.nodes('//RowGroup') Tbl(Col)
SELECT * FROM @tempTable
Here is the XML:
<?xml version="1.0" encoding="UTF-8" ?>
<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd">
<ReportHeader>
</ReportHeader>
<Group Level="1">
<GroupHeader>
<Section SectionNumber="0">
<Text Name="Text4"><TextValue>DELIVERY SCHEDULE</TextValue>
</Text>
<Field Name="DataTime2" FieldName="DataTime"><FormattedValue>09:00:04</FormattedValue><Value>09:00:04</Value></Field>
<Field Name="DataDate2" FieldName="DataDate"><FormattedValue>10/02/2020</FormattedValue><Value>2020-02-10</Value></Field>
<Picture Name="Picture1" GraphicType="OLE">
</Picture>
<Text Name="Text13"><TextValue>DELIVERY ADDRESS</TextValue>
</Text>
<Text Name="Text8"><TextValue>SUPPLIER ADDRESS</TextValue>
</Text>
</Section>
<Section SectionNumber="1">
<Text Name="Text5"><TextValue>our details
</TextValue>
</Text>
<Field Name="WHS2" FieldName="{@WHS}"><FormattedValue>customer details
UK</FormattedValue><Value> customer details2
UK</Value></Field>
</Section>
<Section SectionNumber="2">
<Text Name="Text7"><TextValue>IMPORTANT
EACH ORDER REQUIRES A SEPERATE DELIVERY NOTE PER DELIVERY ADDRESS
</TextValue>
</Text>
</Section>
</GroupHeader>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<GroupFooter>
<Section SectionNumber="1">
<CrossTab Name="CrossTab2">
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">PART0</RowTotal>
<RowTotal RowNumber="1">PART1</RowTotal>
<RowTotal RowNumber="2">PART2</RowTotal>
<RowTotal RowNumber="3">PART3</RowTotal>
<RowTotal RowNumber="4">PART4</RowTotal>
<RowTotal RowNumber="5">PART5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
<ColumnGroups>
<ColumnGroup>
<ColumnGroup>
<ColumnTotal ColumnNumber="0"></ColumnTotal>
<ColumnTotal ColumnNumber="1"></ColumnTotal>
<ColumnTotal ColumnNumber="2"></ColumnTotal>
<ColumnTotal ColumnNumber="3"></ColumnTotal>
<ColumnTotal ColumnNumber="4"></ColumnTotal>
<ColumnTotal ColumnNumber="5"></ColumnTotal>
</ColumnGroup>
</ColumnGroup>
</ColumnGroups>
<Cells>
<Cell RowNumber="0" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>40</FormattedValue><Value>40.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>40</FormattedValue><Value>40.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>20</FormattedValue><Value>20.00</Value></CellValue>
</Cell>
<Cell RowNumber="1" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>40</FormattedValue><Value>40.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="2" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>50</FormattedValue><Value>50.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="3" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>40</FormattedValue><Value>40.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="4" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>40</FormattedValue><Value>40.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>20</FormattedValue><Value>20.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>20</FormattedValue><Value>20.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue>
</Cell>
<Cell RowNumber="5" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>10</FormattedValue><Value>10.00</Value></CellValue>
</Cell>
</Cells>
</CrossTab>
</Section>
</GroupFooter>
</Group>
<Group Level="1">
<GroupHeader>
<Section SectionNumber="0">
<Text Name="Text4"><TextValue>DELIVERY SCHEDULE</TextValue>
</Text>
<Field Name="DataTime2" FieldName="DataTime"><FormattedValue>09:00:04</FormattedValue><Value>09:00:04</Value></Field>
<Field Name="DataDate2" FieldName="DataDate"><FormattedValue>10/02/2020</FormattedValue><Value>2020-02-10</Value></Field>
<Picture Name="Picture1" GraphicType="OLE">
</Picture>
<Text Name="Text13"><TextValue>DELIVERY ADDRESS</TextValue>
</Text>
<Text Name="Text8"><TextValue>SUPPLIER ADDRESS</TextValue>
</Text>
</Section>
<Section SectionNumber="1">
<Text Name="Text5"><TextValue>our details
</TextValue>
</Text>
<Field Name="WHS2" FieldName="{@WHS}"><FormattedValue>customerdetails2
UK</FormattedValue><Value>customer details 2
UK</Value></Field>
</Section>
<Section SectionNumber="2">
<Text Name="Text7"><TextValue>IMPORTANT
EACH ORDER REQUIRES A SEPERATE DELIVERY NOTE PER DELIVERY ADDRESS
</TextValue>
</Text>
</Section>
</GroupHeader>
<Group Level="2">
</Group>
<GroupFooter>
<Section SectionNumber="1">
<CrossTab Name="CrossTab2">
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">P22031</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
<ColumnGroups>
<ColumnGroup>
<ColumnGroup>
<ColumnTotal ColumnNumber="0"></ColumnTotal>
</ColumnGroup>
</ColumnGroup>
</ColumnGroups>
<Cells>
<Cell RowNumber="0" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>4</FormattedValue><Value>4.00</Value></CellValue>
</Cell>
</Cells>
</CrossTab>
</Section>
</GroupFooter>
</Group>
<Group Level="1">
<GroupHeader>
<Section SectionNumber="0">
<Text Name="Text4"><TextValue>DELIVERY SCHEDULE</TextValue>
</Text>
<Field Name="DataTime2" FieldName="DataTime"><FormattedValue>09:00:04</FormattedValue><Value>09:00:04</Value></Field>
<Field Name="DataDate2" FieldName="DataDate"><FormattedValue>10/02/2020</FormattedValue><Value>2020-02-10</Value></Field>
<Picture Name="Picture1" GraphicType="OLE">
</Picture>
<Text Name="Text13"><TextValue>DELIVERY ADDRESS</TextValue>
</Text>
<Text Name="Text8"><TextValue>SUPPLIER ADDRESS</TextValue>
</Text>
</Section>
<Section SectionNumber="1">
<Text Name="Text5"><TextValue>our details
</TextValue>
</Text>
<Field Name="WHS2" FieldName="{@WHS}"><FormattedValue>2nd delivery address
UK</FormattedValue><Value> 2nd delivery address
UK</Value></Field>
</Section>
<Section SectionNumber="2">
<Text Name="Text7"><TextValue>IMPORTANT
EACH ORDER REQUIRES A SEPERATE DELIVERY NOTE PER DELIVERY ADDRESS
</TextValue>
</Text>
</Section>
</GroupHeader>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<Group Level="2">
</Group>
<GroupFooter>
<Section SectionNumber="1">
<CrossTab Name="CrossTab2">
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">Part12</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
<ColumnGroups>
<ColumnGroup>
<ColumnGroup>
<ColumnTotal ColumnNumber="0"></ColumnTotal>
<ColumnTotal ColumnNumber="1"></ColumnTotal>
<ColumnTotal ColumnNumber="2"></ColumnTotal>
<ColumnTotal ColumnNumber="3"></ColumnTotal>
<ColumnTotal ColumnNumber="4"></ColumnTotal>
<ColumnTotal ColumnNumber="5"></ColumnTotal>
</ColumnGroup>
</ColumnGroup>
</ColumnGroups>
<Cells>
<Cell RowNumber="0" ColumnNumber="0">
<CellValue Index="0"><FormattedValue>0</FormattedValue><Value>0.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="1">
<CellValue Index="0"><FormattedValue>5</FormattedValue><Value>5.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="2">
<CellValue Index="0"><FormattedValue>5</FormattedValue><Value>5.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="3">
<CellValue Index="0"><FormattedValue>7</FormattedValue><Value>7.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="4">
<CellValue Index="0"><FormattedValue>6</FormattedValue><Value>6.00</Value></CellValue>
</Cell>
<Cell RowNumber="0" ColumnNumber="5">
<CellValue Index="0"><FormattedValue>5</FormattedValue><Value>5.00</Value></CellValue>
</Cell>
</Cells>
</CrossTab>
</Section>
</GroupFooter>
</Group>
<ReportFooter>
<Section SectionNumber="0">
</Section>
</ReportFooter>
</CrystalReport>
To make matters a little worse, there are two delivery addresses and the bottom section parts (there is only one part) is listed separately. It looks like these are only differentiated by the delivery addresses and nothing else. I think I'm happy to ignore this for now, unless it is easily worked around.
Thanks in advance.