sorting on an expression

I wanted to create a column which was one field divided by another field, and then sort on it.

I started with

Fields!FG.Value)/Fields!ADU.Value

but of course when ADU was 0 it caused an error. then I went to

=iif( Fields!ADU.Value =0,0,(Fields!FG.Value)/Fields!ADU.value)

but sadily it evaluates both the true and the false return values before figuring out which one it would need to return. So then I used this.

=iif( Fields!ADU.Value =0,0,Fields!FG.Value/ iif(Fields!ADU.Value=0,1,Fields!ADU.value))

Which actually works and returns what I would expect it to. Then I go into the report properties and say that I wish to sort on an expression, and enter the above expression. It fails with the following error

"An error has occurred during report processing.

The processing of sort expression for the table 'table1' cannot be performed. The comparison failed. Please check the data type returned by sort expression."

Does anyone have any ideas?

[1597 byte] By [christopher_m] at [2008-2-22]
# 1
Use the following expression instead:

=iif( Fields!ADU.Value = 0, 0.0, CDbl(Fields!FG.Value/ iif(Fields!ADU.Value=0, 1, Fields!ADU.value)))

-- Robert

RobertBrucknerMSFT at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server Reporting Services...

SQL Server

Site Classified