iif statement do nothing - sql-server

I am trying to return nothing for a false statement. Is there a way to do this?
iif(a=1, "Yes", null) <--- this obviously didn't work, but is there anything else that returns nothing if it evaluates a statement as false?

If this is in an SSRS expression then you can use the following
=IIF(Fields!myField.Value = 1, "Yes", nothing)
nothing in SSRS expressions is similar to NULL
For example you can set a textbox background color to nothing which is the same as selecting 'no color' on the property drop down.

Related

Lua UI Text == multiple string's with or's

Now im really new to lua and need a little help with this This script checks some text on the player UI, and It works if It equals one thing for example : game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD"
But does not work if I add the or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or "TANKTOP" It ends up doing it no matter what, and im not sure why, it works if I only put one name though, I would appreciate help thanks!
You already had the same question closed just few days ago due to the lack of details. It's not clear WHY you'd want to add "or" to a text, so you need to explain clearly and provide an example with some context where this usage would make some sense.
In terms of the "or" statement, it doesn't produce the result you want because it returns the first result that is evaluated as non-false, so when you have 1 or 2 expression, the result is 1, as it's evaluated left-to-right and this is a non-false results. Similarly in your case, the expression "UNIVERSELORD" or "TANKTOP" is evaluated to "UNIVERSELORD", as it's the first non-false value that is encountered.
Unfortunately nobody can tell you what to change it to, as there is not enough details in the question about your goal. Possibly an XY Problem.
[updated] Based on your comment, you need to split the or into two complete comparisons: game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "TANKTOP"
In Lua, any value that is not nil or false is considered true.
So in
if (game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or "TANKTOP") then
getgenv().Spinloop = false print("Stopped!") return 0;
end
"TANKTOP" is a string and hence a true value.
or-ing anything with a true value is always true. So it does not matter if game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text equals "UNIVERSELORD". The result is always true. Hence your if condition is always met regardless of the text value.

Hide or show SSRS component based on multivalue parameter

I have an SSRS report that is based on a parameter that can have multiple values. For example: '0','1' and '0','2' (like an IN statement).
Now, I have to show certain parts in the the report whenever the parameter is 0 AND 1, and hide certain parts in the report whenever the parameter is 0 AND 2.
But… This 0 value is always the issue here. I know I have to use the visibility expression for this, but I cannot seem to write the correct expression.
So, when my parameter (Parametername = Prognosis) is (0 and 1), I need the component to show. When my parameter is (0 and 2), I need the component to hide. By the way, it is never just '0', or just '1', or just '2'.
I tried this, but no success:
=IIF(Parameters!Prognosis.Value(0) = 0 and Parameters!Prognosis.Value(0) = 1,False,IIF(Parameters!Prognosis.Value(0) = 0 and Parameters!Prognosis.Value(0) = 2,True,False))
Could someone help me with writing this expression?
Thank you guys
Use join() to put the values of the parameter into a string. So it would be..
=join(Parameters!Thingy.Value, ",")
Then you can see what values are returned by the string. e.g.
=iif(join(Parameters!Thingy.Value, ",") = "0,1", TRUE, FALSE)

Visibility IIF statement rdlcreports

I have a report with a textfield "copy" in it. This should be hidden when my dataset field "isPrinted" is false.
So i tried this one under the expression of the hidden option of the textfield property:
=IIf(First(Fields!isPrinted.Value , "DataSet1")=false)
Obviously im doing something wrong, but I have no idea what.
Anyone who would be so kind to help me in the right direction here ?
Hidden is expecting a result to return TRUE if you want it hidden. The IIF() is typically
IIF( some condition, return this if true, return this if false ).
So, if you want the label HIDDEN, you probably want to remove the IIF(). If the "isPrinted.Value" is a boolean, you MIGHT just be able to do based on something like
=First(Fields!isPrinted.Value, "DataSet1")
or (! logical NOT) if the reverse
=!First(Fields!isPrinted.Value, "DataSet1")

PowerBuilder: Checkbox in DataWindow

I have a checkbox in the DataWindow, It can be checked and unchecked. The default value in the db is 0. When it's checked, the db value is updated to 1 and on uncheck, the value is updated to 0 again.
However, I want to update the database only if it has value 0. If it is already 1, then I don't want the user to be able to change it back to 0. So please tell me how can I do that?
Here is the code from my DataWindow for the checkbox column:
column=(type=decimal(0) update=yes updatewhereclause=yes name=ok dbname="table.ok" values="1/0" )
You could protect the checkbox to prevent unchecking it : in the general / protect field of your checkbox :
if(ok = 1, 1, 0)
Once the checkbox has been checked, it becomes protected (you still have to update the data to the base).
On the next retrieve, you can see that the checkbox is already protected.
You might have to use a similar expression for the Pointer to show that the field is blocked, for example with the NoPointer! cursor.
try using:
if( upper(ok) = 'OFF', 1, 0)
or the other way around:
if(upper(ok) = 'ON', 1, 0)
depending on how you set the on/off values in the properties of the check box.
Note I'm using PowerBuilder 2017

Add alternating row color to SQL Server Reporting services report

How do you shade alternating rows in a SQL Server Reporting Services report?
Edit: There are a bunch of good answers listed below--from quick and simple to complex and comprehensive. Alas, I can choose only one...
Go to the table row's BackgroundColor property and choose "Expression..."
Use this expression:
= IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent")
This trick can be applied to many areas of the report.
And in .NET 3.5+ You could use:
= If(RowNumber(Nothing) Mod 2 = 0, "Silver", "Transparent")
Not looking for rep--I just researched this question myself and thought I'd share.
Using IIF(RowNumber...) can lead to some issues when rows are being grouped and another alternative is to use a simple VBScript function to determine the color.
It's a little more effort but when the basic solution does not suffice, it's a nice alternative.
Basically, you add code to the Report as follows:
Private bOddRow As Boolean
'*************************************************************************
' -- Display green-bar type color banding in detail rows
' -- Call from BackGroundColor property of all detail row textboxes
' -- Set Toggle True for first item, False for others.
'*************************************************************************
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
Then on each cell, set the BackgroundColor as follows:
=Code.AlternateColor("AliceBlue", "White", True)
Further Reading: Report Solution Patterns and Recipes: Greenbar Reports | Wrox
I got the chess effect when I used Catch22's solution, I think because my matrix has more than one column in design.
that expression worked fine for me :
=iif(RunningValue(Fields![rowgroupfield].Value.ToString,CountDistinct,Nothing) Mod 2,"Gainsboro", "White")
I have changed #Catch22's solution A bit as I do not like the idea of having to go into each field if I decide I want to change one of the colors. This is especially important in reports where the are numerous fields that would need to have the color variable changed.
'*************************************************************************
' -- Display alternate color banding (defined below) in detail rows
' -- Call from BackgroundColor property of all detail row textboxes
'*************************************************************************
Function AlternateColor(Byval rowNumber as integer) As String
Dim OddColor As String = "Green"
Dim EvenColor As String = "White"
If rowNumber mod 2 = 0 then
Return EvenColor
Else
Return OddColor
End If
End Function
Noticed that I have change the function from one that accepts the colors to one that contains the colors to be used.
Then in each field add:
=Code.AlternateColor(rownumber(nothing))
This is much more robust than manually changing the color in each fields' background color.
One thing I noticed is that neither of the top two methods have any notion of what color the first row should be in a group; the group will just start with the opposite color from the last line of the previous group. I wanted my groups to always start with the same color...the first row of each group should always be white, and the next row colored.
The basic concept was to reset the toggle when each group starts, so I added a bit of code:
Private bOddRow As Boolean
'*************************************************************************
' -- Display green-bar type color banding in detail rows
' -- Call from BackGroundColor property of all detail row textboxes
' -- Set Toggle True for first item, False for others.
'*************************************************************************
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
'
Function RestartColor(ByVal OddColor As String) As String
bOddRow = True
Return OddColor
End Function
So I have three different kinds of cell backgrounds now:
First column of data row has =Code.AlternateColor("AliceBlue", "White", True) (This is the same as the previous answer.)
Remaining columns of data row have =Code.AlternateColor("AliceBlue", "White", False) (This, also, is the same as the previous answer.)
First column of grouping row has =Code.RestartColor("AliceBlue") (This is new.)
Remaining columns of grouping row have =Code.AlternateColor("AliceBlue", "White", False) (This was used before, but no mention of it for grouping row.)
This works for me. If you want the grouping row to be non-colored, or a different color, it should be fairly obvious from this how to change it around.
Please feel free to add comments about what could be done to improve this code: I'm brand new to both SSRS and VB, so I strongly suspect that there's plenty of room for improvement, but the basic idea seems sound (and it was useful for me) so I wanted to throw it out here.
for group headers/footers:
=iif(RunningValue(*group on field*,CountDistinct,"*parent group name*") Mod 2,"White","AliceBlue")
You can also use this to “reset” the row color count within each group. I wanted the first detail row in each sub group to start with White and this solution (when used on the detail row) allowed that to happen:
=IIF(RunningValue(Fields![Name].Value, CountDistinct, "NameOfPartnetGroup") Mod 2, "White", "Wheat")
See: http://msdn.microsoft.com/en-us/library/ms159136(v=sql.100).aspx
Michael Haren's solution works fine for me. However i got a warning saying that "Transparent" is not a valid BackgroundColor when Preview. Found a quick fix from
Setting BackgroundColor of Report elements in SSRS. Use Nothing instead of "Transparent"
= IIf(RowNumber(Nothing) Mod 2 = 0, "Silver", Nothing)
The only effective way to solve this without using VB is to "store" the row grouping modulo value within the row grouping (and outside the column grouping) and reference it explicitly within your column grouping. I found this solution at
http://ankeet1.blogspot.com/2009/02/alternating-row-background-color-for.html
But Ankeet doesn't the best job of explaining what's happening, and his solution recommends the unnecessary step of creating a grouping on a constant value, so here's my step-by-step process for a matrix with a single row group RowGroup1:
Create a new column within the RowGroup1. Rename the textbox for this to something like RowGroupColor.
Set the Value of RowGroupColor's textbox to
=iif(RunningValue(Fields![RowGroupField].Value
,CountDistinct,Nothing) Mod 2, "LightSteelBlue", "White")
Set the BackgroundColor property of all your row cells to
"=ReportItems!RowGroupColor.Value"
Set the width of the the RowGroupColor column to 0pt and set CanGrow
to false to hide it from clients.
Voila! This also solves a lot of the problems mentioned in this thread:
Automatic resets for subgroups: Just add a new column for that
rowgroup, performing a RunningValue on its group values.
No need to worry about True/False toggles.
Colors only held in one place for easy modification.
Can be used interchangeably on row or column groups (just set height to 0 instead of width)
It would be awesome if SSRS would expose properties besides Value on Textboxes. You could just stuff this sort of calculation in a BackgroundColor property of the row group textboxes and then reference it as ReportItems!RowGroup.BackgroundColor in all of the other cells.
Ahh well, we can dream ...
My problem was that I wanted all the columns in a row to have the same background. I grouped both by row and by column, and with the top two solutions here I got all the rows in column 1 with a colored background, all the rows in column 2 with a white background, all the rows in column 3 with a colored background, and so on. It's as if RowNumber and bOddRow (of Catch22's solution) pay attention to my column group instead of ignoring that and only alternating with a new row.
What I wanted is for all the columns in row 1 to have a white background, then all the columns in row 2 to have a colored background, then all the columns in row 3 to have a white background, and so on. I got this effect by using the selected answer but instead of passing Nothing to RowNumber, I passed the name of my column group, e.g.
=IIf(RowNumber("MyColumnGroupName") Mod 2 = 0, "AliceBlue", "Transparent")
Thought this might be useful to someone else.
I think this trick is not discussed here. So here it is,
In any type of complex matrix, when you want alternate cell colors, either row wise or column wise,
the working solution is,
If you want a alternate color of cells coloumn wise then,
At the bottom right corner of a report design view, in "Column
Groups", create a fake parent group on 1 (using expression), named
"FakeParentGroup".
Then, in the report design, for cells that to be colored
alternatively, use following background color expression
=IIF(RunningValue( Fields![ColumnGroupField].Value, countDistinct, "FakeParentGroup" ) MOD 2, "White", "LightGrey")
Thats all.
Same for the alternate color row wise, just you have to edit solution accordingly.
NOTE: Here, sometimes you need to set border of cells accordingly, usually it vanishes.
Also dont forget to delete value 1 in report that came into pic when you created fake parent group.
If for the entire report you need an alternating color, you can use the DataSet your Tablix is bound to for a report-wide identity rownumber on the report and use that in the RowNumber function...
=IIf(RowNumber("DataSet1") Mod 2 = 1, "White","Blue")
#Aditya's answer is great, but there are instances where formatting will be thrown off if the very first cell of the row (for row background formatting) has a missing value (in complex tablixes with column/rows groups and missing values).
#Aditya's solution cleverly leverages countDistinct result of runningValue function to identify row numbers within a tablix (row) group. If you have tablix rows with missing value in the first cell, runningValue will not increment countDistinct result and it will return the previous row's number (and, therefore, will affect the formatting of that cell). To account for that, you will have to add an additional term to offset the countDistinct value. My take was to check the first running value in the row group itself (see line 3 of the snippet below):
=iif(
(RunningValue(Fields![RowGroupField].Value, countDistinct, "FakeOrRealImmediateParentGroup")
+ iif(IsNothing(RunningValue(Fields![RowGroupField].Value, First, "GroupForRowGroupField")), 1, 0)
) mod 2, "White", "LightGrey")
Hope this helps.
Could someone explain the logic behind turning rest of the fields to false in below code (from above post)
One thing I noticed is that neither of the top two methods have any notion of what color the first row should be in a group; the group will just start with the opposite color from the last line of the previous group. I wanted my groups to always start with the same color...the first row of each group should always be white, and the next row colored.
The basic concept was to reset the toggle when each group starts, so I added a bit of code:
Private bOddRow As Boolean
'*************************************************************************
'-- Display green-bar type color banding in detail rows
'-- Call from BackGroundColor property of all detail row textboxes
'-- Set Toggle True for first item, False for others.
'*************************************************************************
'
Function AlternateColor(ByVal OddColor As String, _
ByVal EvenColor As String, ByVal Toggle As Boolean) As String
If Toggle Then bOddRow = Not bOddRow
If bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
'
Function RestartColor(ByVal OddColor As String) As String
bOddRow = True
Return OddColor
End Function
So I have three different kinds of cell backgrounds now:
First column of data row has =Code.AlternateColor("AliceBlue", "White", True) (This is the same as the previous answer.)
Remaining columns of data row have =Code.AlternateColor("AliceBlue", "White", False) (This, also, is the same as the previous answer.)
First column of grouping row has =Code.RestartColor("AliceBlue") (This is new.)
Remaining columns of grouping row have =Code.AlternateColor("AliceBlue", "White", False) (This was used before, but no mention of it for grouping row.)
This works for me. If you want the grouping row to be non-colored, or a different color, it should be fairly obvious from this how to change it around.
Please feel free to add comments about what could be done to improve this code: I'm brand new to both SSRS and VB, so I strongly suspect that there's plenty of room for improvement, but the basic idea seems sound (and it was useful for me) so I wanted to throw it out here.
I tried all these solutions on a Grouped Tablix with row spaces and none worked across the entire report. The result was duplicate colored rows and other solutions resulted in alternating columns!
Here is the function I wrote that worked for me using a Column Count:
Private bOddRow As Boolean
Private cellCount as Integer
Function AlternateColorByColumnCount(ByVal OddColor As String, ByVal EvenColor As String, ByVal ColCount As Integer) As String
if cellCount = ColCount Then
bOddRow = Not bOddRow
cellCount = 0
End if
cellCount = cellCount + 1
if bOddRow Then
Return OddColor
Else
Return EvenColor
End If
End Function
For a 7 Column Tablix I use this expression for Row (of Cells) Backcolour:
=Code.AlternateColorByColumnCount("LightGrey","White", 7)
Just because none of the answers above seemed to work in my matrix, I'm posting this here:
http://reportingservicestnt.blogspot.com/2011/09/alternate-colors-in-matrixpivot-table.html
My matrix data had missing values in it, so I wasn't able to get ahmad's solution to work, but this solution worked for me
Basic idea is to create a child group and field on your innermost group containing the color. Then set the color for each cell in the row based on that field's value.
Slight modification of other answers from here that worked for me. My group has two values to group on, so I was able to just put them both in the first arg with a + to get it to alternate correctly
= Iif ( RunningValue (Fields!description.Value + Fields!name.Value, CountDistinct, Nothing) Mod 2 = 0,"#e6eed5", "Transparent")
When using row and column groups both, I had an issue where the colors would alternate between the columns even though it was the same row. I resolved this by using a global variable that alternates only when the row changes:
Public Dim BGColor As String = "#ffffff"
Function AlternateColor() As String
If BGColor = "#cccccc" Then
BGColor = "#ffffff"
Return "#cccccc"
Else
BGColor = "#cccccc"
Return "#ffffff"
End If
End Function
Now, in the first column of the row you want to alternate, set the color expression to:
=Code.AlternateColor()
-
In the remaining columns, set them all to:
=Code.BGColor
This should make the colors alternate only after the first column is drawn.
This may (unverifiably) improve performance, too, since it does not need to do a math computation for each column.

Resources