Home All Groups Group Topic Archive Search About
Author
1 Sep 2006 3:42 AM
dwasserman
I am wondering if it is possible to output another field in a database
from within a case statement, i.e.:

CASE
When Exam_Requirements = 'Y' then Exam_Comments

The goal would be for each return of a yes in exam requirements the
exam comments would extract?

Thanks,
George

Author
1 Sep 2006 4:07 AM
Tom Cooper
Yes, if you mean output the value of the Exam_Comments when
Exam_Requirements = 'Y', otherwise output something else (if desired, the
something else can be NULL).  Something like

use pubs
Select au_id,
state,
Case When state = 'CA' Then city
  Else '' End As CalifCity
From authors
Order By au_id

Tom

<dwasser***@nd.edu.au> wrote in message
Show quote
news:1157082125.417569.248220@74g2000cwt.googlegroups.com...
>I am wondering if it is possible to output another field in a database
> from within a case statement, i.e.:
>
> CASE
> When Exam_Requirements = 'Y' then Exam_Comments
>
> The goal would be for each return of a yes in exam requirements the
> exam comments would extract?
>
> Thanks,
> George
>
Author
1 Sep 2006 4:11 AM
Uri Dimant
Hi
create table #test (id int not null primary key,c1 char(1) ,c2 varchar(50))

insert into #test values (1,'Y','etetetetete')
insert into #test values (2,'N','etetetetete')
insert into #test values (3,'Y','etetetetete')


select *, case when c1 ='Y' then c2 else 'sorry' end as blablabla
from #test





<dwasser***@nd.edu.au> wrote in message
Show quote
news:1157082125.417569.248220@74g2000cwt.googlegroups.com...
>I am wondering if it is possible to output another field in a database
> from within a case statement, i.e.:
>
> CASE
> When Exam_Requirements = 'Y' then Exam_Comments
>
> The goal would be for each return of a yes in exam requirements the
> exam comments would extract?
>
> Thanks,
> George
>
Author
1 Sep 2006 4:20 AM
Martin Poon [MVP]
The syntax will be similar to:

SELECT
    CASE
        WHEN MyTable01.Exam_Requirements = 'Y' THEN MyTable02.Exam_Comments
        -- convert to the same type as Exam_Comments
        WHEN MyTable01.Exam_Requirements = 'N' THEN convert(nvarchar(100),
'blank, or return something')
        ELSE convert(nvarchar(100), 'Error?')
        END as MyExamComments
    FROM MyTable01, MyTable02, ...
    WHERE ...

- CASE (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms181765.aspx

--
Martin C K Poon
Microsoft MVP - SQL Server
----------------------------------------------------------
<dwasser***@nd.edu.au> wrote in message
Show quote
news:1157082125.417569.248220@74g2000cwt.googlegroups.com...
>I am wondering if it is possible to output another field in a database
> from within a case statement, i.e.:
>
> CASE
> When Exam_Requirements = 'Y' then Exam_Comments
>
> The goal would be for each return of a yes in exam requirements the
> exam comments would extract?
>
> Thanks,
> George
>

AddThis Social Bookmark Button