Archives

Archives / 2008 / August
  • SQL Not In Revisited

    I always seem to struggle with a NOT IN clause when there are more than one column to compare.  This, of course, comes up when I am trying to get records from one set that are NOT IN another set and the comparison has to be done across multiple columns.  For instance, if I want to compare table 1 (users) against table 2 (importedUsers) and I want to see if the mandatory fields are there and *NOT* work with those that fail I usually ended up doing a cursor.  But - there is a much easier way to do it and it does need a cursor!  Thanks to David Penton for pointing me in this direction!

  • SQL XML - TreeView

    I sometimes forget how to do an XML output formed in a tree when dealing with a single table parent/child relationship.  There is a great explanation on SQL Server Central on *how* to do this.  I am mainly capturing the link and the SQL I just generated to do this.  This query will drill down 12 levels at the most.  Just alter the case statement (pivot) to go deeper.