Skip site navigation (1) Skip section navigation (2)

Re: case stement when null

From: "Riccardo G(dot) Facchini" <abief_ag_-postgresql(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: case stement when null
Date: 2004-06-19 06:21:38
Message-ID: 20040619062138.5995.qmail@web13904.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-sql
--- Jaime Casanova <__> wrote:
> hi all,
> 
> Well i rethink my design 'cause the other was too slow. but all
> solutions 
> involves new problems... now my problem is with a function of this
> type:
> 
> 
> CREATE OR REPLACE FUNCTION
> "public"."rec_f_consultarplanificacionrubros" 
> (smallint, smallint, char(9), smallint, smallint, smallint, char(2))
> RETURNS 
> SETOF "public"."rec_td_rubrosplanificados" AS '
>     select rub_codigo, cpa_valor, cpa_fechavencimiento
>          from rec_m_cuadropagosciclo
> 		where ent_codigo = $1
> 		  and sec_codigo = $2
> 		  and ani_codigo = $3
> 		  and case $4
>                    when null then cic_codigo IN (select cic_codigo
> from 
> aca_m_cicloaniolectivo
>                                                         where
> ent_codigo = 
> $1
>                                                           and
> sec_codigo = 
> $2
>                                                           and
> ani_codigo = 
> $3)
>                    else cic_codigo = $4
>               end
> ' LANGUAGE 'sql'
> 
> but when $4 is null the function executes the else part and what i
> want to 
> do is to execute the when null. Can you help me???

try the form:

case
  when $4 is null
    then cic_codigo IN
         (select cic_codigo
            from aca_m_cicloaniolectivo
           where ent_codigo = $1 and
                 sec_codigo = $2 and
                 ani_codigo = $3)
    else cic_codigo = $4
end

[]

regards,



=====
Riccardo G. Facchini

In response to

pgsql-sql by date

Next:From: V i s h a l Kashyap @ [Sai Hertz And Control Systems]Date: 2004-06-19 10:20:05
Subject: Re: case stement when null
Previous:From: Riccardo G. FacchiniDate: 2004-06-19 06:03:30
Subject: Re: plpgsql - Insert from a record variable?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group