Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

transact sql - case when "any row returned for sql"

1 view
Skip to first unread message

metaperl

unread,
Oct 22, 2009, 1:05:28 PM10/22/09
to
Hello, I have a need to setup a CASE statement in Sybase (Transact)
SQL where one of my branches is like this:


SELECT
CASE WHEN
(SELECT * FROM table WHERE column = 'FY' AND person_id=74) --
<----- problem line
THEN 'OK'
ELSE
'BAD'


I think I figured out a way to do it, per
http://msdn.microsoft.com/en-us/library/ms181765.aspx

Maybe this will work:

CASE
SELECT COUNT(*) FROM table WHERE column = 'FY' AND person_id=74)
WHEN 0 THEN 'BAD'
ELSE 'OK'

--CELKO--

unread,
Oct 23, 2009, 10:03:57 AM10/23/09
to
On Oct 22, 12:05 pm, metaperl <scheme...@gmail.com> wrote:
> Hello, I have a need to setup a CASE statement in Sybase (Transact)
> SQL where one of my branches is like this:
>
> SELECT
>   CASE WHEN
>       (SELECT * FROM table WHERE column = 'FY' AND person_id=74)   --
> <----- problem line
>       THEN 'OK'
>   ELSE
>       'BAD'
>
> I think I figured out a way to do it, perhttp://msdn.microsoft.com/en-us/library/ms181765.aspx

>
> Maybe this will work:
>
> CASE
>     SELECT COUNT(*) FROM table WHERE column = 'FY' AND person_id=74)
>     WHEN 0 THEN 'BAD'
>      ELSE 'OK'

There is not such thing as a CASE statement in SQL; there is a CASE
expression. Expressions return scalar values of one type. WHEN
clauses have to have search conditions. Is this what you meant?

SELECT
CASE WHEN
EXISTS (SELECT * FROM Foobar
WHERE some_column = 'FY'
AND person_id = 74)
THEN 'OK' ELSE 'BAD' END, ...

metaperl

unread,
Oct 28, 2009, 4:19:29 PM10/28/09
to
On Oct 23, 10:03 am, --CELKO-- <jcelko...@earthlink.net> wrote:
> On Oct 22, 12:05 pm, metaperl <scheme...@gmail.com> wrote:
>
>
>
> > Hello, I have a need to setup a CASE statement in Sybase (Transact)
> > SQL where one of my branches is like this:
>
> > SELECT
> >   CASE WHEN
> >       (SELECT * FROM table WHERE column = 'FY' AND person_id=74)   --
> > <----- problem line
> >       THEN 'OK'
> >   ELSE
> >       'BAD'
>
> > I think I figured out a way to do it, perhttp://msdn.microsoft.com/en-us/library/ms181765.aspx
>
> > Maybe this will work:
>
> > CASE
> >     SELECT COUNT(*) FROM table WHERE column = 'FY' AND person_id=74)
> >     WHEN 0 THEN 'BAD'
> >      ELSE 'OK'
>
> There is not such thing as a CASE statement in SQL; there is a CASE
> expression.  

ok. understood.

> Expressions return scalar values of one type.  WHEN
> clauses have to have search conditions.  Is this what you meant?
>
>  SELECT
>    CASE WHEN
>      EXISTS (SELECT * FROM Foobar
>                   WHERE some_column = 'FY'
>                       AND person_id = 74)
>      THEN 'OK'   ELSE  'BAD' END, ...

Yes, that will work. Thanks.

0 new messages