I have a number of fields in one column of my table. I have it if field1 is blank display field2 and so on, What i trying to do now is if all fields are blank display N/A.
What i have tried below;
=IFF(ISNothing(Fields!field1.Value) & IIF(IsNothing(Fields!field2.Value),"N/A",VbCRLF & Fields!field2.Value))
What this sometimes displays is field1N/A.
Can anyone point me in the right direction?
Thanks,
UPDATE 1:
I have also tried;
=IFF(ISNothing(Fields!field1.Value),"N/A",Fields!field1.Value & IIF(IsNothing(Fields!field2.Value),"N/A",VbCRLF & Fields!field2.Value))
That also did not work.
There are two ways to do this. You can either handle it in SQL Server Query or in the SSRS
Method 1: TSQL
You can use the COALESCE function to find the first non null value. Replace it with N/A if all are NULLs
SELECT COALESCE(Field1, Field2, Field3, 'N/A') AS newFieldValue, ....
FROM myTable.....
WHERE ....
Method 2: SSRS
There is no COALESCE equivalent in SSRS. You can either use iif or switch to emulate the logic.
=SWITCH(NOT(ISNothing(Fields!field1.Value)), Fields!field1.Value,
NOT(ISNothing(Fields!field2.Value)), Fields!field2.Value,
NOT(ISNothing(Fields!field3.Value)), Fields!field3.Value,
1=1, "N/A")
Also remember if there is space in the field, it won't be handled by ISNULL function. In that case you will also need to use the similar logic to handle the empty spaces.
HTH.
I'd suggest what you need is ISNULL.
Example usage as follows:
ISNULL(su.address1_line2, 'N/A')
This will find null values in that column and replace them with N/A in the report
Related
I have a multi-select.
I think the underlying datatype is int || array(int). This is pretty frustrating that you have to do a check to see if a multi-value is present before jumping into an index. But how does this value get passed to SQL?
It's easy enough to use in a IN (#variable) statement. How else can it be used? Is it a string or a table. From my investigations it appears to be single table row with many un-named columns but I'm not really sure.
Finally, when you want to simulate a multi-select in a query inside visual studio, for example to "Refresh Fields" how do you do that? For example "1,2,3", {1,2,3} or #{1,2,3}. It's not (123) because that is -123.
It dpends what you are trying to do and in what context.
As you said, if you have a datset query that is a SQL script (as opposed to a stored proc) then you can use IN(#paramName). In this instance SSRS take the parameter values (not the labels) and injects them into the sql statement as a string e.g. '1,2,3'. The result would be IN(1,2,3). If you want to pass in a list of, say, countries then you would have to set the parameter values to be the same as the parameter labels So rather then Value =1, Label = Spain you would have Value = Spain and Label = Spain. Used in an IN() would generate something like IN('Spain', 'France').
If you try to do the same with a stored proc e.g. EXEC myProc #myParam, then the parameter values would be passed as a sing string which would then need to be split out by the proc.
If you just want to get a list of selected parmeter values or label shoing in your report then you can simply do something like
=JOIN(Parameters!myParam.Value, ",")
or
=JOIN(Parameters!myParam.Label, ",")
where "," is the delimiter
If you pop this expression in a text box, you'll get a list of the selected parmater values/labels
I think it's a kind of madness but I found a workaround to get a table of values from the results from SSRS. I query the IDs against a source table using IN(). I hope there is a better way of doing this?
SELECT [TblFeeBillingCycleID]
FROM [TblFeeBillingCycle]
WHERE [TblFeeBillingCycleID] IN(#intCycleId)
Hello i tried using both switch as well as iif function in ssrs report. I have a column(Delta) which has values and need to set image depending on column values. Below is my switch statement
=Switch(
Fields!Delta.Value =0,"arrowzero.jpg",
Fields!Delta.Value >0,"arrowup.jpg",
Fields!Delta.Value <0,"arrowup.jpg",
Fields!Delta.Value ="CNC","arrowblack.jpg"
)
Switch statement is working for all cases except last case "CNC".
A couple of observations that might help you fix this.
You switch statement uses the same column however the first three evaluate it numerically, the last one against a string. Is this correct?
Is the image called "arrowblack.jpg", is there a typo here?
If the last option is supposed be act like an ELSE then you can replace Fields!Delta.Value ="CNC","arrowblack.jpg" with True,"arrowblack.jpg"
I'm amalgamating several manual reports into one SSRS one by changing the select statements to follow a set format of:
select
'DepartmentName'
,'StatName'
,'DataType' --(Int, percentage,date,time, etc)
,'Stat'
from TablesNeeded
Now this unions together fine so I end up with a list of statistic names and their values. After this I want to have the cell showing "Stat" to change it's formatting based on the result of "DataType"
I attempted to use an IIF to determine the format, which behaved with a single IIF statement, however after nesting to accomodate different data taypes it appears to "false" every IIF result and return just the default/value:
Working
=iif(
Fields!DataType.Value="Percentage"
,Format(Fields!Stat.Value,"0%")
,Fields!Stat.Value
)
"Falsing"
=iif(
Fields!DataType.Value="Percentage"
,Format(Fields!Stat.Value,"0%")
,iif(
Fields!DataType.Value="Date"
,Format(Fields!Stat.Value,"y")
,iif(
Fields!DataType.Value="int"
,Fields!Stat.Value
,Fields!Stat.Value
)))
and using switch similarily also "Falsed"
=Switch(
Fields!DataType.Value="Percentage",Format(Fields!Stat.Value,"0%")
,Fields!DataType.Value="int",Format(Fields!Stat.Value,"#,#0")
,Fields!DataType.Value="Date",Format(Fields!Stat.Value,"y")
)
I've asked a colleague and we're both stumped. Any ideas on proper expression formats?
Assuming all your datatypes are correct then you just need to use a simplified version of your switch statement in the Format property of the cell(s).
Something like..
=SWITCH(
Fields!DataType.Value="Percentage","0%"
,Fields!DataType.Value="int","#,#0"
,Fields!DataType.Value="Date","y")
)
Note You could just use "p0" for you percentage type, "n0" for your int.
I am trying to filter a query using a temporary variable that is inside an IN() condition. The temporary variable contains a list of text values. I am using the macro-builder tool in Access 2010.
Assume I have a query qryMain that produces:
Field1 Field2
1 A
4 B
2 C
3 D
without a WHERE clause. Using the clause
WHERE [tblMain].[Field2] IN([TempVars]![tmpField2])
to filter the query, the desired results are
Field1 Field2
1 A
4 B
when tmpField2 is set to "A,B". I set tmpField2 using an on-click event in form frmMain using SetTempVar and Requery the subform/subreport object sfrmMain that is based on qryMain. This is done via the MS macro-builder, not VBA.
Unfortunately, requerying sfrmMain produces an empty table rather than the expected results. Note that if I set tmpField2 to "A", then the requery macro works as expected.
I have tried multiple variations of initializing tmpField2, based on Access's double quote requirements, but still no success. My question is similar to this as-yet unanswered question, but my question involves passing the temp variable inside an IN() statement within the WHERE clause, without using VBA.
The problem is not actually due to TempVars. If your value list came from a form's text box instead of TempVars, the result would be the same.
For what you're attempting to do, IN () requires a hard-coded list of values:
SELECT m.Field1, m.Field2
FROM tblMain AS m
WHERE m.Field2 IN ('A','B');
But, instead of a hard-coded list of values, you want to supply the list dynamically when the query is run:
WHERE m.Field2 IN (something_dynamic);
Unfortunately, Access will not cooperate. Whatever you supply for something_dynamic, Access will interpret it to be only one value ... not a list of values. And it doesn't matter what method you use to supply something_dynamic ... a TempVar, a text box, a formal query parameter, a custom VBA function which returns a string containing a list of values ... that list will be evaluated as only a single value.
If you were willing to use VBA, you could write the query at runtime to include a hard-coded value list before executing it. Since you want to avoid VBA, you can try something like this ...
WHERE InStr(1, [TempVars]![tmpField2], "'" & m.Field2 & "'") > 0
Note that approach requires quoting text values within tmpField2: 'A','B'
Also beware that approach could be painfully slow with a large table. Access would need to evaluate that InStr expression for every row in the table.
I am facing very simple issue but not getting solution over it.
I have textbox in my ssrs report, I am passing value "1;prashant" or null to it. Now, if I pass value "1;prashant" to textbox then textbox should show only "prashant" and If I am passing nothing then it should be blank.
I have tried following IIF condition:
=IIF(IsNothing(FieldS!WIAPPORVER.Value),"",Split(Fields!WIAPPORVER.Value,"#")(1).ToString())
But, I above code is giving an error ["#error" shows in textbox] if I am passing blank value.
Please let me know, where I am wrong in this.
Thanks
There are probably better ways of doing this, but this is what my head came up with at the time:
=IIF(
IsNothing(Fields!WIAPPROVER.Value)
,""
,Right(Fields!WIAPPROVER.Value,Len(Fields!WIAPPROVER.Value) -InStr(Fields!WIAPPROVER.Value,";"))
)
I believe SSRS is trying to compute everything in the report at runtime, so in your case it is still trying to fetch index 1 from an array even though there is nothing in it and it crashes.
Edit: Changed parameters to Fields. I created a parameter to remake the issue at my side.
Just get the split out of the iif. Then in your iif, if field is nothing create a string that when split will return ""
=Split(IIF(IsNothing(FieldS!WIAPPORVER.Value),"#", Fields!WIAPPORVER.Value),"#")(1)
You are relying on the IIf expression short circuiting, but SSRS IIf expressions do not short circuit - the expression will try and work out Split(Fields!WIAPPORVER.Value,"#")(1).ToString() for all rows and fail when this value doesn't exist.
You can get this going by using text expressions, which don't get this error.
With test data:
And a simple table:
I have added columns with both your existing expression and a new expression:
=Right(Fields!WIAPPORVER.Value, Len(Fields!WIAPPORVER.Value) - InStr(Fields!WIAPPORVER.Value, "#"))
This new expression works for NULL values, empty strings and strings with no delimiter present: