Report Builder Expression with a ' - sql-server

I have this field called series that has this expression in it, what does the ' mean in this context?
=(Fields!PropertyID.Value)
'=IIF(Parameters!CombineProperties.Value = TRUE AND (Fields!Campus.Value<>""),Fields!Campus.Value,Fields!PropertyName.Value)

This is an SSRS expression for a label or variable that is parsed at runtime in an ssrs report. The gist here is :
The starting =(Fields!PropertyID.Value) does not make sense as you can't set variables that way, however, after the ' it goes like this:
var result=null;
if (CombineProperties && Campus.Length > 0)
result=Campus
else
result=PropertyName
After reading your post again, I think you are trying to Concatenate strings. Is this your end goal?
=CSTR(Fields!PropertyID.Value) + IIF((Parameters!CombineProperties.Value = True) AND (Fields!Campus.Value<>""), Fields!Campus.Value,Fields!PropertyName.Value)
Update
Doh!, I am rusty on VB. I believe apostrophe comments out a line. Everything after ' is ignored. DOH!

Related

Reactjs convert input string to upper case

I'm creating an app in Reactjs using react-strap. I would like to convert an input field to upper case.
From googling, it looks like simply appending "toUpperCase()" to the field would work, but this doesn't appear as an option in Visual Studio code.
I had a similar issue with doing a replace all, but finally got that to work using "const" field:
// replace ":" with "-"
const phrase = item.macs;
const replaced = phrase.replace(/:/g, '-')
item.macs = replaced;
However, converting to a const field doesn't work for making the "toUpperCase()" available.
What should I do to turn this into a string so I can call the "toUpperCase()" function?
Edit: change references from "toUpper" to "toUpperCase". The problem is this is not available as a function.
For example of I do
'myString'.toUpperCase();
it works. But it I can't get it to bring that up in Visual Studio Code, and it's ignored if I code it anyway.
I believe you are looking after toUpperCase.
To make a string uppercase in javascript you can call .toUpperCase() method on it. For example
const foo = 'foo'
const fooUpper = foo.toUpperCase()
console.log(fooUpper) // expected result 'FOO'
I got around this problem by forcing the input item to be regarded as a string by prepending it with a '', like so:
item.macs = '' + item.macs;
item.macs = item.macs.replace(/:/g, '-');
item.macs = item.macs.toUpperCase();
After that, all the string functions were available.

Check if a string contains all other strings

I am trying to code a part of a software where I try to show the results that match search criteria.
I have a textbox where I can type one or more words I want to search and a listview that contains 4 different columns and a dozen rows. The idea is that each listview row contains lots of words and I want to see only the rows that contain all the words I have typed in the textbox. I have finished the code that searches for one term only. The problem I am having is that I don't fully understand how to do the same, but using multiple terms instead of one term only.
In the textbox, I write the words I want to search separated by a space. I have a variable where I keep the whole content of the listview row separated by : (example => col1row1content:col1row2content:col1row3content,etc). Summarizing, I want to check if a string (the full content of a row) contains all other strings (each word I have typped in the textbox).
This is the code I have implemented:
Dim textboxFullContentArray As String() = textboxSearch.Split(New Char() {" "c})
Dim Content As String
Dim containsAll As Boolean = False
Dim wholeRowContent(listviewMain.Items.Count - 1) As String ' each index of the array keeps the entire row content (one array contains all 4 cells of the row)
' wholeRowContent contains in one index the entire content of a row. That means,
' the index contains the 4 cells that represent an entire row.
' The format is like "rowData1:rowData2:rowData3:rowData4" (omitted for simplicity)
For Q As Integer = 0 To listviewMain.Items.Count - 1
For Each Content In textboxFullContentArray
If wholeRowContent(Q).ToLower.Contains(Content) Then
containsAll = True
' rest of the code...
ElseIf Not wholeRowContent(Q).ToLower.Contains(Content) Then
containsAll = False
Exit For
End If
Next
Next
But of course, this code is showing false positives and I think it's not a good solution. I think it must be much easier and I am overcomplicating the concept.
I am using VB.Net 2013
You can determine whether a String contains all of a list of substrings with a single line of code:
If substrings.All(Function(s) str.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0) Then
Notice that I have actually implemented a case-insensitive comparison, rather than using ToLower or ToUpper.
It may not seem as neat to call IndexOf rather than Contains but guess what: Contains actually calls IndexOf internally anyway:
public bool Contains(string value)
{
return this.IndexOf(value, StringComparison.Ordinal) >= 0;
}
You can write your own extension methods if you want a case-insensitive Contains method:
<Extension>
Public Function Contains(source As String,
value As String,
comparisonType As StringComparison) As Boolean
Return source.IndexOf(value, comparisonType) >= 0
End Function
Your If/Else looks like it could be simplified. I would set your containsAll value to true outside the nested loops, and only if you encounter a "Content" in "textboxFullContentArray" that is not contained in wholeRowContent(Q) you set containsAll to false, otherwise do nothing.
Also, one way to see what's going on is to print statements with the values that are being compared throughout your function, which you can read through and see what is happening at runtime when the false positives occur.
After some hours looking for a simple and effective solution (and trying different codes), I have finally found this solution that I adapted from: Bad word filter - stackoverflow
For Q As Integer = 0 To listviewMain.Items.Count - 1
If textboxFullContentArray.All(Function(b) wholeRowContent(q).ToLower().Contains(b.ToLower())) Then
' my code
End If
Next

SSRS expression for empty parameter value returns #Error

I have a parameter in report that I recently changed it to accept NULL values. It was a required parameter before but now it is not required. Header in the report has below expression to read data from the parameter value. Ever since I modified the parameter to accept NULLvalues, it is erroring out. It shows #Error in the header. I have tried modifying the expression to display result even if the parameter is 'NULL', but nothing has worked so far. I am pretty much stuck here. Here is the expression I am using in SSRS:
=IIF(Code.MultipleValues(Parameters!ProductID.Value(0))="True"
,IIF(IsNothing(First(Fields!ProductName.Value, "ProductHeader")),""
,First(Fields!ProductName.Value, "ProductHeader")).ToString
,IIF(Len(Parameters!ProductID.Value(0)) > 0
,IIF(First(Fields!ProductName.Value, "ProductHeader") is nothing,""
,First(Fields!ProductName.Value, "ProductHeader")),"All Products Selected"))
I believe the error has to do with the VB custom code that is in the report. I am not too familar with the code so I am having trouble troubleshooting it.
VB code:
Public Function MultipleValues(ByVal str As String) As String
If str.Contains(",")
Return "True"
Else
Return "False"
End If
End Function
Any suggestion on how to handle #Error in SSRS? thanks
Replace
Code.MultipleValues(Parameters!ProductID.Value(0))="True"
with
IndexOf(Parameters!ProductID.Value(0).ToString(),",") >= 0
Instead of a function, can you just put the IsNothing check in front of the parameter ?
=IIF(Code.MultipleValues(IsNothing(Parameters!ProductID.Value(0),""))="True"

How to Display Page Number in Report Body of SSRS 2008 R2?

I think a lot of developers are facing the problem of try to display page numbers by using SSRS 2008 R2.
There is an alternative solution which requires SSRS 2010 + version. Otherwise you will get 1 all the time.
Go to "Report" -> "Report Properties" -> "Code"
In the Custom Code section, enter the following:
Public Function PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function
Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function
Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:
="Page " + Code.PageNumber() + " of " + Code.TotalPages()
This solution DOES NOT work with SSRS 2008 R2.
However there is a workaround, it will work with any version higher than 2008 R2 (include 2008 R2). I will post as an answer, hope it will help some people whoever struggling with this issue.
First you need to use report variables:
right click on the empty space of report -> Variables -> Create a variable such as PageCount (set default value to 0)
Then in you header or footer -> create a textbox and set expression ->
=Variables!PageCount.SetValue(Variables!PageCount.Value+1)
It will automatically increase for each page.
(IMPORTANT: DO NOT hide it from header or footer, the SetValue WON'T work if you hide the box, so change the font to 1 or text to white, do whatever, just DO NOT hide it (it will print 'True' as the setting took places))
Then you can use:
=Variables!PageCount.Value
at any part of your report body to access the page number.
IMPORTANT: Please NOTE that I tried to use Globals!PageNumber to set the variable but ends up it was NOT accessible from report body. So, it has to be something both accessible from Header/Footer OR Body.
In my case, I have to reset the Page number per each instance of my Group.
So I just set a trigger at the end of the group.
(e.g. I check if I have my Total value returns, because i know for each end of my group i will have a Total display.
Because of in function IIF both True and False part will be processed, so if you put setters in IIF such as below:
=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),Variables!PageCount.SetValue(0))
)
you will ends up have value 0 all the time, because the report will Check the True Part then the False part, both setters will be executed (value will be set twice)
so we need 2 boxes and something like:
(You have to hide unnecessary box your checking conditions)
=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),"")
)
You need to hide this box when NOT IsNothing(ReportItems!TotalBox.Value)
=IIF(NOT IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(0),"")
)
Again you need to hide this box when IsNothing(ReportItems!TotalBox.Value)
Of course you could use some other way to determine the end of a group instance, like:
make a textbox which ONLY contains a fixed value at the end of your group table. and hide it. when you checking the trigger just do the similar approach as I do.
It works fine for all versions above 2008 R2 (included).
If you are using SQL Server 2016 Report Builder, this expression worked with me.
=Globals!PageNumber.ToString() +"/" + Globals!TotalPages.ToString()
Here is working expression:
=Microsoft.VisualBasic.Interaction.Switch(Parameters!LANGUAGE.Value = "en-US", "Page " + code.PageNumber().ToString() + " of " + code.TotalPages().ToString(), Parameters!LANGUAGE.Value = "es-MX", "Hoja " + code.PageNumber().ToString() + " de " + code.TotalPages().ToString(), 1 = 1, "Page " +code.PageNumber().ToString() + " of " + code.TotalPages().ToString())
In Visual Studio 2013 Report variables will be Visible under Report menu.
From Main Menu - Report > ReportProperties > Variables > Add
First Follow the steps 1 below to do pagination:
1)
1.1. Click the Details group in the Row Groups pane.
1.2. From the Tablix member Properties pane, expand “Group”-> “PageBreak”.
1.3. Set the “BreakLocation” to “End” and set the “Disable” property to the expression like below:
=IIF(rownumber(nothing) mod 40=0,false,true)
The above point 1 is use to do pagination in Report output(Display only 40 records per page in output)
2) use custom code:
Public Function PageNumberno(val as integer) as String
Dim str as String
str =(val/40)
Return str
End Function
3) Create Calculated column in Dataset and enter =0 in expression
4) In 2 Calculated Column
1)Pageno
2)No
in Dataset
In Report Body use Expression for PageNo :
=code.PageNumberno(Rownumber("DataSet1"))
use Expression for No :
=IIF(Instr(code.PageNumberno(Rownumber("DataSet1"))
,".")<>0,
(Left(code.PageNumberno(Rownumber("DataSet1")),
(Instr(code.PageNumberno(Rownumber("DataSet1")),".")-1))+1)
,code.PageNumberno(Rownumber("DataSet1"))
)
5)Right click and insert column on Right Side and in Column name add code in Text box
=ReportItems!No.Value
Note: No is calculated Field column name.
6)Under AdvancedMode IN Row Group select Static and Set RepeatOnNewPage Properties to True
In the Above Column created under point 5 will display correct page no in every page in body of the report
I have Tried and its working Fine..Try it.

ssis variable not evaluating

I have a variable that concatenates a file path into a string , and i can't get it to evaluate the concatenation. when i display the value of the variable in a script task, i still see all the double quote marks (see below). I have set the evaluateasexpression for the variable to true.
When i try to use this variable as a sql command, the error is:
"invalid syntax near the +"
(i believe this is the plus sign below the redactedcol3 below)
BTW, is property expressions the only place where you can evaluate a variable's value as you are developing? (expression builder).
This is how the variable displays in the message box in the script component:
"SELECT redactedcol1,redactedcol2,rtrim(" + "'" + #user::LocalPath + " + "'" + "+[redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Not entirely sure this is what you want, but I think it is:
"SELECT redactedcol1,redactedcol2,rtrim("
+ "'"
+ #user::LocalPath
+ "'"
+ " + [redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Note the removed extraneous plus sign and double-quote. (I find it helps when concatenating in SSIS to put each part on its own line.)
And I also recommend BIDS Helper, a free tool that includes a better (IMO) expression building GUI, as well as Konesans' Expression Editor which is a like a mini-Intellisense workbench for expressions.
There's also a Variables window in SSIS Projects (View -> Other Windows -> Variables) where you can see the evaluated value of a variable expression.
For others wondering why their expression is not evaluating...
http://www.sqlchicken.com/2012/02/ssis-expressions-not-evaluating-correctly/
Click on the Variable. Make sure "EvaluateAsExpression" is True

Resources