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.

Sybase version of DECODE and creating cross-tab queries

2 posts in Windows NT Last posting was on 2000-05-17 18:52:03.0Z
Patrick Siconolfi Posted on 2000-05-16 18:41:57.0Z
Reply-To: "Patrick Siconolfi" <psiconolfi@janna.com>
From: "Patrick Siconolfi" <psiconolfi@janna.com>
Subject: Sybase version of DECODE and creating cross-tab queries
Date: Tue, 16 May 2000 14:41:57 -0400
Lines: 13
Organization: Janna Systems
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Message-ID: <XanR8e2v$GA.70@forums.sybase.com>
Newsgroups: sybase.public.sqlserver.nt
NNTP-Posting-Host: 204.138.158.254
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.sqlserver.nt:2161
Article PK: 1089585

Is there any way to return a cross tab query in Sybase. By that I mean
conducting a query on a tall thin table and returning a fat short recordset.
I know that in Oracle the DECODE statment is used. Is there a similar
function in Sybase SQL Server 11.3 to do the same thing?

The DECODE statement basically does an if, then, else on every record. The
following is the syntax for DECODE

DECODE(if criteria, then value, else value)


Tommy Phillips Posted on 2000-05-17 18:52:03.0Z
Message-ID: <3922EA53.1D70B1F0@sybase.com>
Date: Wed, 17 May 2000 12:52:03 -0600
From: Tommy Phillips <tommy@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.5 [en]C-CCK-MCD (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: Sybase version of DECODE and creating cross-tab queries
References: <XanR8e2v$GA.70@forums.sybase.com>
Content-Type: multipart/mixed; boundary="------------F764C5E1527C89DB5A85825D"
Newsgroups: sybase.public.sqlserver.nt
Lines: 38
NNTP-Posting-Host: tommy-lpt.sybase.com 157.133.56.58
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.sqlserver.nt:2154
Article PK: 1089591

Use the CASE expression:

SELECT CASE t1.val
WHEN 1 THEN 'One'
WHEN 2 THEN 'Two'
WHEN 3 THEN 'Three'
ELSE 'Bad data'
END
FROM t1

There are other variants of the CASE expression, but this is the most frequently used form.

Patrick Siconolfi wrote:
>
> Is there any way to return a cross tab query in Sybase. By that I mean
> conducting a query on a tall thin table and returning a fat short recordset.
> I know that in Oracle the DECODE statment is used. Is there a similar
> function in Sybase SQL Server 11.3 to do the same thing?
>
> The DECODE statement basically does an if, then, else on every record. The
> following is the syntax for DECODE
>
> DECODE(if criteria, then value, else value)


Download VCard tommy.vcf