dbTalk Databases Forums  

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

comp.databases comp.databases


Discuss transact sql - case when "any row returned for sql" in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
metaperl
 
Posts: n/a

Default transact sql - case when "any row returned for sql" - 10-22-2009 , 12:05 PM






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'

Reply With Quote
  #2  
Old   
--CELKO--
 
Posts: n/a

Default Re: transact sql - case when "any row returned for sql" - 10-23-2009 , 09:03 AM






On Oct 22, 12:05*pm, metaperl <scheme... (AT) gmail (DOT) 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, ...

Reply With Quote
  #3  
Old   
metaperl
 
Posts: n/a

Default Re: transact sql - case when "any row returned for sql" - 10-28-2009 , 02:19 PM



On Oct 23, 10:03*am, --CELKO-- <jcelko... (AT) earthlink (DOT) net> wrote:
Quote:
On Oct 22, 12:05*pm, metaperl <scheme... (AT) gmail (DOT) 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.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.