Solved

cfif statment inside query

Posted on 2011-02-16
6
514 Views
Last Modified: 2012-05-11
so im looping through my query...

<cfoutput>
            <cfloop query="SQL">
<td>#Value_1#</td>
<td>#Value_2#</td>
<td>#Value_3#</td>
<td>  #Value_4#  </td>  <!-- What i want to do here is for value 5 -->
<td><cfif  #Value_4#.currentrow  = 'X'> #Value_5#  <cfelse> #Value_6#</td>
</cfif>
</tr>
</cfloop>
</cfoutput>
so I need to check Value_4 for each row to see if its X. If it is display value 5 for that row , if not display  Value 6

Please Help

0
Comment
Question by:plusone3055
6 Comments
 
LVL 19

Expert Comment

by:Jones911
ID: 34912851
OK and whats failing?
0
 
LVL 1

Expert Comment

by:medsoos
ID: 34912916
Try using 'is' instead of the equal (=) sign.
0
 
LVL 3

Accepted Solution

by:
sajayc earned 500 total points
ID: 34913021
Hi,

Couple of things:
- You don't need the .currentrow and the closing </cfif> needs to be inside the td.
- The correct operator inside the if statement is eq for =.

Code below should work.

<cfoutput>
            <cfloop query="SQL">
<td>#Value_1#</td>
<td>#Value_2#</td>
<td>#Value_3#</td>
<td>  #Value_4#  </td>  <!-- What i want to do here is for value 5 -->
<td><cfif  Value_4 eq "X"> #Value_5# <cfelse>#Value_6#</cfif> </td>
</tr>
</cfloop>
</cfoutput>

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 63

Expert Comment

by:Zvonko
ID: 34913029
Get that end of table cell out of cfelse branch:

<td>
<cfif  #Value_4# EQ  'X'>
   #Value_5#  
<cfelse>
   #Value_6#
</cfif>
</td>
</tr>

And remove the .currentrow from column value in the cfif compare.

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 34913034
Sorry, too slow typing.
0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 34913467
so I need to check Value_4 for each row to see if its X. If it is display value 5 for that row , if not display  Value 6

If your value_4 and X are strings, then use compare function

<td>
<cfif NOT compareNoCase('#value_4#','X')>
	#value_5#
<cfelse>
	#value_6#
</cfif>
</td>
</tr>

Open in new window


0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question