Posts

Showing posts with the label SQL Server

A good use of Common Table Expressions

Image
The problem I had a situation recently were I needed to find a set of data that was structured logically as a tree and was stored as a single table.   I had an initial id and I needed to search for children of this id.   Then I needed to use the children’s ids and search for their children.   This continued until there were no more children of an id.   This structure could have a plethora of different sets of children. For examples the boxes below represent an id and I only show three levels deep but the level depth was not restricted: Once I found all of an id’s children, I needed to do some manipulation of this data.   To make this problem easier to understand and use a ubiquitous example, the ids will be folders and there are files (stored in another table) associated with the folders.   Therefore for this problem, I need to find all the child folders for a specific folder, the files associated with the initial folder and the files associated wi...

XML Entity References

Some symbols cannot be used with XML because most XML parsers will choke on them usually throwing an error.  So you must replace these symbols with their entity reference.  An entity reference begins with an ampersand and ends with a semi-colon and in between includes a multi-character code that represents the original value. Less than (<): replace with &lt; Greater than (>): replace with &gt; Ampersand (&): replace with &amp; Apostrophe ('): replace with &apos; Quotation mark ("): replace with &quot;