Skip to main content
February 2, 2008
Question

CFCase and CFSwitch

  • February 2, 2008
  • 3 replies
  • 349 views
so i've got this query that returns some values. i want to check one of the values #LongDescription# to see if it's EQ "" or NEQ "". if it's NEQ "", i want it to output P/N and #LongDescription, sum the #ExtPrice#, or output #PartNumber# and #Description# and loop thru this process until i hit a #PartNumber# EQ #Subtotal#. when it hits subtotal, i want it to output the text MODULEPRICE & SubTotal and populate these fields with something looks like this:

96310 N.T. SPEC. UV-2EC DAPI FILER SET 1

96311 N.T. SPEC B2-EC FITC FILTER SET 1

96313 N.T. Y2-EC TEXAS RED FILTER SET 1

Module Price $20,751.05 Subtotal $20,751.05

This allows me to keep a running total and break a quote into'logical' units so if some module isn't needed, the customer can do his own math and just send me the po. i've tried cfif's and cfloop's and cfswitch's till my little punkin head is about to 'splode
    This topic has been closed for replies.

    3 replies

    Inspiring
    February 4, 2008
    The other respondents seem to be giving you suitable answers.

    But for a broader response, the first thing you should be doing if you're
    having trouble with something is to read the docs.

    CFSWITCH
    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_r-s_23.html

    CFCASE
    http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_c_03.html#3798974

    If you do that, then quite often you can solve the problem yourself. You
    got a quick answer on this one, so no problems from any point of view, but
    sometimes questions here go unanswered for a while, which can leave you
    bogged down unnecessarily.

    --
    Adam
    Participating Frequently
    February 4, 2008
    Hi Scamp,

    The cfwitch/case tag requires you to evaluate something specific in your case a query column. Per switch statement you can only evaluate ONE expression.

    <cfswitch expresssion="#myquery.column#">

    <cfcase value="something">
    <!--- do something --->
    </cfcase>

    </cfcase value="somthingelse">
    <--- do something else --->
    </cfcase>
    <cfdefaultcase>
    <!--- something unexpected happend do something unexpected --->
    </cfdefaultcase>
    </cfwitch>


    Inspiring
    February 2, 2008
    I would just use cfif. By the way you do not need the # signs.

    <cfif Quote.LongDescription neq "">
    blank table here
    <cfelse>
    table with data here
    </cfif>



    "Scamp" <webforumsuser@macromedia.com> wrote in message
    news:fo2i11$gpr$1@forums.macromedia.com...
    > so i've got this query that returns some values. i want to check one of
    > the
    > values #LongDescription# to see if it's EQ '' or NEQ ''. if it's NEQ '',
    > i
    > want it to output P/N and #LongDescription, sum the #ExtPrice#, or output
    > #PartNumber# and #Description# and loop thru this process until i hit a
    > #PartNumber# EQ #Subtotal#. when it hits subtotal, i want it to
    > output
    > the text MODULEPRICE & SubTotal and populate these fields with
    > something
    > looks like this: 96310 N.T. SPEC. UV-2EC DAPI FILER SET 1 96311 N.T.
    > SPEC
    > B2-EC FITC FILTER SET 1 96313 N.T. Y2-EC TEXAS RED FILTER SET 1
    > Module
    > Price $20,751.05 Subtotal $20,751.05 This allows me to keep a running
    > total
    > and break a quote into'logical' units so if some module isn't needed, the
    > customer can do his own math and just send me the po. i've tried cfif's
    > and
    > cfloop's and cfswitch's till my little punkin head is about to 'splode
    >
    > <p align="left"><cfoutput query="Quote"><cfset Subtotal = 0>
    > <table width="100%" border="1" cellspacing="2" cellpadding="5">
    > <cfswitch>
    > <cfcase #Quote.LongDescription# NEQ "">
    > <tr>
    > <td width="15%"><strong>#Quote.PartNumber#</strong></td>
    > <td width="85%"><strong>#Quote.LongDescription#</strong></td>
    > <cfset #subtotal# eq (#subtotal# + #Quote.ExtPrice#)>
    > </tr>
    > </cfcase>
    > <cfcase #Quote.LongDescription# EQ "">
    > <tr>
    > <td width="15%"><strong>#Quote.PartNumber#</strong></td>
    > <td width="85%"><strong>#Quote.Description#</strong></td>
    > <cfset #subtotal# eq (#subtotal# + #Quote.ExtPrice#)>
    > </tr>
    > </cfcase>
    > <cfcase #Quote.PartNumber# eq "subtotal">
    > <tr>
    > <td width="15%"><strong>#Quote.PartNumber#</strong></td>
    > <td width="85%"><strong>#Subtotal#</strong></td>
    > </tr>
    > </cfcase>
    > </tr>
    > </table>
    > </cfswitch>
    > </cfoutput>
    >