Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3709A475A6B for ; Wed, 28 Aug 2002 13:44:53 -0400 (EDT) Received: from sterling.betterhealthfoundation.net (user-112ugh2.biz.mindspring.com [66.47.66.34]) by postgresql.org (Postfix) with ESMTP id 55FF2475974 for ; Wed, 28 Aug 2002 13:44:52 -0400 (EDT) Received: from dinar ([192.168.1.12]) by sterling.betterhealthfoundation.net with Microsoft SMTPSVC(5.0.2195.4905); Wed, 28 Aug 2002 10:44:57 -0700 From: "Tom Haddon" To: Subject: Case Statement Date: Wed, 28 Aug 2002 10:44:57 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) In-Reply-To: <200208281701.g7SH1aI20777@candle.pha.pa.us> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-OriginalArrivalTime: 28 Aug 2002 17:44:57.0172 (UTC) FILETIME=[9FCD7140:01C24EBA] X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/402 X-Sequence-Number: 9248 Hi Folks, I am having troubles with a case statement in that I want to have the query select only those records that match a particular case. Here's my query: SELECT agency_contact_info.id,organization,department,city,state,description_of_ser vices, CASE WHEN agency_contact_info.id > 0 THEN 0 ELSE 0 END + CASE WHEN agency_contact_info.languages_other_text ~ 'Mien' THEN 1 ELSE 0 END AS relevance FROM agency_contact_info WHERE (agency_contact_info.guideregion=1 AND list_online IS TRUE AND (agency_contact_info.id > 0 OR agency_contact_info.languages_other_text ~ 'Mien' )) ORDER BY relevance DESC, agency_contact_info.organization How do I add in the fact that I only want records where the CASE (as relevance) > 0? I've tried using it in the WHERE statement adding a HAVING statement and it doesn't like either. You will see a fair amount of redundancy in the statement above such as "CASE WHEN agency_contact_info.id > 0 THEN 0 ELSE 0 END" and "agency_contact_info.id > 0" - this is because it is being built dynamically, and it makes it easier to build the addition blocks of the statement. Thanks in advance, Tom _______________________________ Tom Haddon IT Director The Better Health Foundation 414 Thirteenth Street, Suite 450 Oakland, CA 94612 (510) 444-5096 www.betterhealthfoundation.org _______________________________