title: Disassembling Bit Flag Enumerations in SQL Server
body: <p>I have an <code>INT</code> column in a SQL Server database which stores a value relating to a bit flag enumeration. For instance, if the enum is:</p>
  
  <pre><code>[Flags()]
  public enum UserType
  {
      StandardUser = 1,
      Admin = 2,
      SuperUser = 4
  }
  </code></pre>
  
  <p>then the column in SQL Server might hold a value of 5.</p>
  
  <p>What I need to do is select all of the rows from another table holding additional details about the <code>UserType</code>, so using the example of a value of 5, I would want to select the rows from the second table with IDs 1 and 4.</p>
  
  <p>Does anyone know a clever way to break the number up in this manner - ideally the method should be recursive to some degree since this is a very simplified example, and the actual tables/enums are much bigger.</p>