Gossamer Forum
Home : General : Databases and SQL :

SQL conditional IF, help with

Quote Reply
SQL conditional IF, help with
I havethis query

<CFQUERY name="getFundStatus" datasource="xxx">
SELECT (IIf(paybycheck.anonym=1, "anonym", paybycheck.name)) AS name,
city,state,amount,checkdate,anonym
FROM paybycheck
WHERE fund = '#tpcid#'
group by name,city,state,amount,anonym,checkdate
order by name asc
</CFQUERY>

returns "-1" instead of the word "anonym" AS name


I have also tried

SELECT
case when paybycheck.anonym=1 then 'anonym' else paybycheck.name end AS name
FROM paybycheck
WHERE 1=1

and this

SELECT
CASE paybycheck.anonym
WHEN 1 then 'anonym'
WHEN 0 then paybycheck.name
END as name
FROM paybycheck
WHERE 1=1

and a host of variations, at no avail.
These last two, keeps generating the "missing operator in query espression" error.

Any thought?

Thank You
Quote Reply
Re: [walterc] SQL conditional IF, help with In reply to
one quick fix would be using the conditions in your CFOUTPUT section.

Example:

Code:
<cfoutput query="getFundStatus">
<cfif (#anonym# eq 1)>
Anonymous
<cfelse>
#name#
</cfif>
</cfoutput>
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Stealth: May 21, 2003, 4:30 PM