Saturday, September 06, 2008

Auto XML sorted

I've been fighting a bug for some hours now bug have finally found the solution!

Here's the deal: I've developed a tool to import the contents of some files into a database. Furthermore there is a UI for CRUD'ing the now database content. The problem was, that when I imported from more than 10 files (don't know why this exact number, it's purely empirical) the data would show up pretty strange. It should have a format like this:

1 (count: 34)
3 (count: 54)
2 (count: 20)

But instead it was showing:

1 (count: 1)
2 (count: 1)
1( count: 1)
1 (count: 1)
3 (count:1)
... etc.

Weird!

At first I was looking at the import tool - I must have made an error somewhere, but no. The solution was to sort the data! The stored procedure selecting the data uses FOR XML AUTO to generate a hierachical structure, and somehow that twisted the data. But after adding "ORDER BY ColumnName" to the SQL it comes out right!

I don't understand why yet - and can't find any other posts regarding the same topic....

No comments: