Main Page | Report this Page
Computers Forum Index  »  Computer - Databases  »  transact sql - case when "any row returned for sql"...
Page 1 of 1    

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

Author Message
metaperl...
Posted: Thu Oct 22, 2009 5:05 pm
Guest
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--...
Posted: Fri Oct 23, 2009 2:03 pm
Guest
On Oct 22, 12:05 pm, metaperl <scheme... at (no spam) gmail.com> wrote:
Quote:
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...
Posted: Wed Oct 28, 2009 8:19 pm
Guest
On Oct 23, 10:03 am, --CELKO-- <jcelko... at (no spam) earthlink.net> wrote:
Quote:
On Oct 22, 12:05 pm, metaperl <scheme... at (no spam) 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.

Quote:
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.
 
 
Page 1 of 1    
All times are GMT
The time now is Mon Nov 30, 2009 11:07 am