Hi,
I have a table with 3 columns MP4, 3G2 and 3GP, all of each have are
bit value types, e.g., True or False values.
MP4 | 3GP | 3G2
False | True | False
I'm trying to create a select statement that will give me the first
column in the table that has a true value.
For example, considering the example above I would like my query to
return '3GP'.
Can somebody help me with this? Thanks.
If you have a single row, something like this will work:
SELECT CASE WHEN [MP4] = 1 THEN 'MP4'
WHEN [3GP] = 1 THEN '3GP'
WHEN [3G2] = 1 THEN '3G2'
END
FROM Foobar
For multiple rows you will get the first column with value 1 (if any) for
each row.
HTH,
Plamen Ratchev
http://www.SQLStudio.com
-----------------------------------------------Reply-----------------------------------------------
AHHH Case is what I was looking for. Thanks!
On May 29, 11:39 am, "Plamen Ratchev" <Pla@SQLStudio.com> wrote:
> If you have a single row, something like this will work:
> SELECT CASE WHEN [MP4] = 1 THEN 'MP4'
> WHEN [3GP] = 1 THEN '3GP'
> WHEN [3G2] = 1 THEN '3G2'
> END
> FROM Foobar
> For multiple rows you will get the first column with value 1 (if any) for
> each row.
> HTH,
> Plamen Ratchevhttp://www.SQLStudio.com