no IF - am I missing something ?

From: "Richard Crawley" <richard(dot)crawley(at)quadronservices(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: no IF - am I missing something ?
Date: 2005-03-17 19:57:53
Message-ID: opsnsserfhyivrd9@richardcgx270.zen.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello all.

In the tail end of converting an app from MySQL to psql. I have this code :

<snip>
IF(days_complete <= -120, job_price,0) AS Days_120,
IF(days_complete BETWEEN -119 AND -90, job_price,0) AS Days_90,
IF(days_complete BETWEEN -89 AND -60, job_price,0) AS Days_60,
IF(days_complete BETWEEN -59 AND -30, job_price,0) AS Days_30,
IF(days_complete BETWEEN -29 AND 0, job_price,0) AS current
<snip>

It builds an aged debt report, and there are similar versions that SUM(IF ..) to give me debt by customer etc.

All the questions I've seen about IF end up with people saying "use CASE" and I'm sure it would work. But do you lot really use 5 lines for each IF ? Doesn't it seem kind of ugly ? Or do you all secretly write a quick IF function ?

I'm interested, and I half suspect that I'm missing a more elegant solution.

thanks

Rich

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2005-03-17 20:55:19 Re: Problems building postgresql 8.0.1 on OS X 10.3.8
Previous Message Kevin Murphy 2005-03-17 19:48:00 mailing list archives not responding?