I have a single row in a table variable that looks like this:
CanEdit | CanView | CanAdd | CanDelete
All columns are bit fields. I need to convert this table to a comma-delimited string like the following:
-
If the user has true for each column…
E,V,A,D -
If the user only has Edit and Add…
E,A
How can I do this?
As it’s a fixed set, it can be done directly as follows.
That said, it is very rare that this is recommended.
If you are refactoring your data, this is reversing the atomicity of your data and is considered a fundamentally problematic anti-pattern in SQL.
If you are doing this for presentation in a client, doing this in SQL couples your data layer and presentation layer, another anti-pattern.