Search code examples
sqlcoldfusion-9

set value with cfif cfelse Coldfusion


I'm trying to set value If it matched the output should be renamed as "INFORMATION AVAILABLE" if not as "NO MATCH".

Thank you for your help and tricks

<cfquery name="gethi" datasource="testdb">
    select resp from t_tes x where service=upper('B76Z7') and rownum <=1
    and resp Like ('%OK%')
</cfquery>

<cfif gethi.resp is "">
    <cfset gethi.resp="INFORMATION AVAILABLE">
    <cfoutput>#gethi.resp#</cfoutput>
<cfelse>
    <cfoutput>gethi.resp="NO MATCH"</cfoutput>
</cfif>

What can be done that it works as requested? any tips? thank you


Solution

  • It seems to me that what you are trying to accomplish is to determine whether the query returns a match or not and to display information on whether a match was found or not.

    I don't see that you actually need to set a query cell. I don't see that you actually need to set any variable.

    <cfquery name="MyQuery" datasource="testdb">
        select resp from t_tes x where service=upper('B76Z7') and rownum <=1
        and resp Like ('%OK%')
    </cfquery>
    
    <cfif MyQuery.RecordCount eq 0>
        NO MATCH
    <cfelse>
        INFORMATION AVAILABLE
    </cfif>