Subject | Re: [firebird-support] Multiply CASE in SQL statement |
---|---|
Author | Svein Erling Tysvær |
Post date | 2006-05-11T11:18:54Z |
Hmm, obviously I didn't do things right when sending a couple of e-mails this morning.
Don't know if all comments are still relevant, but here we go:
---
Hi Majstoru (I'm writing from Majorstua (in Oslo, Norway), almost an
acronym for your nickname).
I don't think you need multilevel CASE for this statement, but yes, it
is possible.
In your case, I'd use something like
SELECT CASE
WHEN A.GROUPFIELD = 1 THEN
A.PRICE
WHEN A.GROUPFIELD = 2 THEN
(SELECT C.Price FROM Catalog C
WHERE C.Article = A.id)
WHEN A.GROUPFIELD = 3 THEN
(SELECT A.Price * P.Param_price FROM ParamsTable P
WHERE P.Date = :DATE)
END as MyResult
FROM ARTICLE A
WHERE A.Id = :ID
I think it is possible to use CASE A.GROUPFIELD WHEN 1.. WHEN 2.. as
well, I'm simply not used to that syntax and cannot bother to try
locating The Firebird book.
HTH,
Set
majstoru wrote:
Don't know if all comments are still relevant, but here we go:
---
Hi Majstoru (I'm writing from Majorstua (in Oslo, Norway), almost an
acronym for your nickname).
I don't think you need multilevel CASE for this statement, but yes, it
is possible.
In your case, I'd use something like
SELECT CASE
WHEN A.GROUPFIELD = 1 THEN
A.PRICE
WHEN A.GROUPFIELD = 2 THEN
(SELECT C.Price FROM Catalog C
WHERE C.Article = A.id)
WHEN A.GROUPFIELD = 3 THEN
(SELECT A.Price * P.Param_price FROM ParamsTable P
WHERE P.Date = :DATE)
END as MyResult
FROM ARTICLE A
WHERE A.Id = :ID
I think it is possible to use CASE A.GROUPFIELD WHEN 1.. WHEN 2.. as
well, I'm simply not used to that syntax and cannot bother to try
locating The Firebird book.
HTH,
Set
majstoru wrote:
> Hi,
>
> I hava a little complicated request from one of my client for a
> Article price.
>
> The request is that I have a 1000 articles (for a sample) each article
> is in one of 5 group of article, each grou have a price category!
>
> For example:
> Group1: SELECT Price FROM Article WHERE Id = :ID
> Group2: SELECT C.Price FROM Catalog C, Article A WHERE C.Article =
> A.id AND A.Id = :ID
> Group3: SELECT A.Price * P.Param_price FROM Articla WHERE P.Date = :
> DATE AND A.Id = :ID
> . . .
>
> Here we are! I need to write a SQL statement which will fetch price
> from one of theese 3 SQL statement which is depent on which article
> group is belong that article!
>
> I think that CASE will solve this but, can I use multiply CASE into
> one SQL statement and if I can, what is sintax?
>
> Thanks for ALL help!