I am writing a report to return details about an object ('files') in my database. My application lets users create their own flags for use against file objects. Flags basically consist of a name, then flag instances store a bit value to indicate whether it is set for the parent file object.
I want to write a query that returns one row per file in the database, where the first few columns in the result set contain the file details (id, name, size etc) and the remaining columns are the flag names, with bit values returned to indicate whether the flag is set for the given file row.
Does that make sense? How do i go about writing the query?
Thanks for any help.
Edit: Clarification..
As part of this query, I need to run a sub query that returns the flags that have been created by the user (I do not know these at design time), then incorporate a check for each flag value in the main query to return details about the files.
Simplified schema as follows:
- File {Id, Name}
- Flag {Id, Name}
- FileFlags {FileId, FlagId} - a row in this table indicates that the flag is set for the file
I need the query to return a result set with columns something like this:
FileId FileName Flag1Name Flag2Name .... FlagNName