Thanks. I figured I was trying to do something not legal in SQL.
I actually wanted to use this when selecting from 2 tables (maybe 1 more) so
it may seem that the attributes vary widly. The tables individually are
normal and do not have widly different attributes. I was just playing with
the idea more than anything else.
--
Ray
"Jeff Mason" <je.mason@a...> wrote in message
news:260413@s..._language...
>
> CASE is an *expression*, not a statement. The distinction is important,
and
> it is the reason (among others) why you can't do what you want to do. An
> expression returns a single value. You have no (real) choice except to
> repeat the expression for each column value you want to include.
>
> Remember too, that a SELECT statement returns a resultset which is a
> *table*, and a table is a set of rows each row of which contains a set of
> columns - the *same* columns. The values in those columns can of course
be
> different. A row is a representation of some entity or process and what
you
> would like to do strikes me as defining a table in which each represented
> entity has wildly different attributes from the others. You will get
> yourself in trouble with such an unnormalized design.
> --
> Jeff Mason Custom Apps, Inc.
> Jeff@c...
>
> -----Original Message-----
> From: Ray [mailto:ray@l...]
> Sent: Tuesday, February 11, 2003 9:45 AM
> To: sql language
> Subject: [sql_language] CASE Statement
>
>
> I know I can use a case statement in the following way
> select sid, case when deptNo=2 then '$' else users_name end from users
> where basically I am saying if the deptNo=2 then get a $ else get the
users
> name.
>
> Is there a way I can select two columns based on the value of sid? For
> instance what if I wanted to choose $,* if deptNo=2 but choose users_name,
> users_title otherwise.
>
> I have tried
> select sid, case when deptNo=2 then '$','*' else
users_name,users_title
> end from users
> and several variations of that but none seem to work. I know I can do a
> second case statement for the second column but I don't want to do that.
> Can you help me?
>
> --
> Ray
>
>
>
>
>
>