pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hengky Lie <hengkyliwandouw@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Need help with CASE statement in Function
Date: Thu, 4 Oct 2007 00:44:04 +0800
Message-ID: <000d01c805dc$9e8db450$1d00a8c0@hengky> (raw)

Dear friends,

 

I am a new user to postgreSQL and really need help to solve my "stupid ?"
problem.

 

I have created  function with 4 arguments like this :

 

CREATE OR REPLACE FUNCTION "public"."fHistoryCard" (begdate date, enddate
date, ProductID varchar, storeID varchar) RETURNS SETOF "public"."tbltrans"
AS

$body$

/* New function body */

 

select * from tbltrans

where tbltrans."Date" between $1 and $2

and upper(tbltrans."ProductID")=upper($3)

and tbltrans."StoreID"=$4

order by tbltrans."Tanggal";

$body$

LANGUAGE 'sql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

 

---------------------

 

My Question is : How to make argument 4 optional ? When IS NULL the function
will show all transaction between date $1 and $2 and product ID=$3 

 

But when $4 is not null then the fucntion will show all transaction between
date $1 and $2 and product ID=$3 AND STOREID=$4.

 

I really appreciate any suggestions.

 

Thanks a lot.

 

Hengky

 

 

view thread (3+ messages)  latest in thread

Message-ID: <000d01c805dc$9e8db450$1d00a8c0@hengky>
Permalink:  ../000d01c805dc$9e8db450$1d00a8c0@hengky/
Also on:    postgresql.org/message-id/000d01c805dc$9e8db450$1d00a8c0@hengky

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: hengkyliwandouw@gmail.com
  Subject: Re: Need help with CASE statement in Function
  In-Reply-To: <000d01c805dc$9e8db450$1d00a8c0@hengky>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox