Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Using CASE statement in GROUP BY

3 posts in General Discussion Last posting was on 2010-01-05 16:17:56.0Z
shahab sharifi Posted on 2010-01-02 10:52:08.0Z
Sender: 6bed.4b3f2350.1804289383@sybase.com
From: shahab sharifi
Newsgroups: sybase.public.ase.general
Subject: Using CASE statement in GROUP BY
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4b3f2558.6c4b.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 2 Jan 2010 02:52:08 -0800
X-Trace: forums-1-dub 1262429528 10.22.241.41 (2 Jan 2010 02:52:08 -0800)
X-Original-Trace: 2 Jan 2010 02:52:08 -0800, 10.22.241.41
Lines: 7
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:28820
Article PK: 78062

hi
In ms sql server it is possible to use a case when ... then
.. statement in group by section of a query an it seems
rather useful. As far as I could search I didn't find an
equivalnet for this feature in ASE 12. I'm eager to know
more about, if there is any way to do so.
thanks for any suggestions


Rob V [ Sybase ] Posted on 2010-01-02 12:59:24.0Z
Reply-To: "Rob V [ Sybase ]" <robv@DO.NOT.SPAM.sypron.nl.REMOVE.THIS.DECOY>
From: "Rob V [ Sybase ]" <robv@DO.NOT.SPAM.sypron.nl.REMOVE.THIS.DECOY>
Newsgroups: sybase.public.ase.general
References: <4b3f2558.6c4b.1681692777@sybase.com>
Subject: Re: Using CASE statement in GROUP BY
Lines: 36
Organization: Sypron BV / TeamSybase / Sybase
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4b3f432c$1@forums-1-dub>
Date: 2 Jan 2010 04:59:24 -0800
X-Trace: forums-1-dub 1262437164 10.22.241.152 (2 Jan 2010 04:59:24 -0800)
X-Original-Trace: 2 Jan 2010 04:59:24 -0800, vip152.sybase.com
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:28821
Article PK: 78063

The CASE expression (technically, in SQL, CASE is not a statement but part
of a statement) has been supported in ASE since version 11.5. It should work
in a GROUP BY. Can you show your example where you're trying to use it but
it's not allowed?

HTH,

Rob V.
-----------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 15.0/12.5/12.0/11.5/11.0
and Replication Server 15.0.1/12.5 // TeamSybase

Author of Sybase books (order online at www.sypron.nl/shop):
"Tips, Tricks & Recipes for Sybase ASE" (ASE 15 edition)
"The Complete Sybase ASE Quick Reference Guide"
"The Complete Sybase Replication Server Quick Reference Guide"

mailto:rob@YOUR.SPAM.sypron.nl.NOT.FOR.ME
http://www.sypron.nl
Sypron B.V., Amersfoort, The Netherlands
Chamber of Commerce 27138666
-----------------------------------------------------------------

<shahab sharifi> wrote in message
news:4b3f2558.6c4b.1681692777@sybase.com...
> hi
> In ms sql server it is possible to use a case when ... then
> .. statement in group by section of a query an it seems
> rather useful. As far as I could search I didn't find an
> equivalnet for this feature in ASE 12. I'm eager to know
> more about, if there is any way to do so.
> thanks for any suggestions


tartampion Posted on 2010-01-05 16:17:56.0Z
Sender: 779c.4b4233f8.1804289383@sybase.com
From: tartampion
Newsgroups: sybase.public.ase.general
Subject: Re: Using CASE statement in GROUP BY
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4b436634.1eda.1681692777@sybase.com>
References: <4b3f2558.6c4b.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 5 Jan 2010 08:17:56 -0800
X-Trace: forums-1-dub 1262708276 10.22.241.41 (5 Jan 2010 08:17:56 -0800)
X-Original-Trace: 5 Jan 2010 08:17:56 -0800, 10.22.241.41
Lines: 32
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:28826
Article PK: 78067

It works here is an example, a table called tt ( a int) has
got the following content:
a
---
1
2
9
19
11
111
The following query produces the results needed:
select a=case when a <10 then 1 when a between 10 and 20
then 10 else 100 end ,number_in_range=sum(1) from tt group
by case when a <10 then 1 when a between 10 and 20 then 10
else 100 end order by 1
a number_in_range
------ ---------------
1 3
10 2
100 1

Ba salam
Tartampion

> hi
> In ms sql server it is possible to use a case when ...
> then ... statement in group by section of a query an it
> seems rather useful. As far as I could search I didn't
> find an equivalnet for this feature in ASE 12. I'm eager
> to know more about, if there is any way to do so.
> thanks for any suggestions