SSRS expression - remove line breaks when field contains no data - ssrs-2008

I have an SSRS report that is a calendar, and it shows each persons different activity for each day. I currently do this via .vbcrlf to create the line break.
What I would like to do is only return a line break when there is data in the specific value.
My current expression is:
=Fields!DayOfMonth.Value
& Constants.vbcrlf
& Constants.vbcrlf
& Fields!Shift.Value
& Constants.vbcrlf
& Fields!OT.Value
& Constants.vbcrlf
& Fields!Holiday.Value
& Constants.vbcrlf
& Fields!AbsenceType.Value
& Constants.vbcrlf
& Fields!ClockIn.Value
So if there is no Holiday I would like to remove that line and the break meaning Absence and In/Out would move up the text box. I've tried using isNothing but cant get the syntax right.

It sees the data as NULL values, which can alter the way it treats text.
You can use iif(isnothing(Field!Thing.Value), "", Constants.vbcrlf & Field!Thing.Value) around each one to replace null values with blanks.
There may be a more elegant solution available.

The syntax which worked for me in VS 2017 with SQL Server Data Tools:
=IIf(Fields!Holiday.Value Is "", "", Fields!Holiday.Value + Environment.NewLine)
+ IIf(Fields!AbsenceType.Value Is "", "", Fields!AbsenceType.Value + Environment.NewLine)
Code is pretty much self explanatory - if there is no value for Holiday, result is empty string or else if it has value, show value and line break. For latest syntax of any function, just refer to the examples given in the Expression window.

Related

Microsoft graph Mail Search Strict value

I have an issue with the search parameters. I want to pass a phrase in my query. For exemple i'm looking for emails where the subject is "Test 1".
For this i'm doing a get on this ressource.
https://graph.microsoft.com/v1.0/me/messages?$search="subject:Test 1"
But the behaviour of this query is : Looking for mails that contains "Test" in the subject OR 1 in any other fields.
Refering to the KQL Syntax
A phrase (includes two or more words together, separated by spaces; however, the words must be enclosed in double quotation marks)
So, to do what i want i have to put double quotes (") around my phrase to do a strict value search. Like below
subject:"Test 1"
The problem it's at this point. Microsoft graph api already use double quotes (") after the parameters $search.
?$search="Key words"
So I can't do what is mentioned in the KQL doc.
https://graph.microsoft.com/v1.0/me/messages?$search="subject:"Test 1""
It's throwing an error :
"Syntax error: character '1' is not valid at position 15 in '\"subject:\"test 1\"\"'.",
It's an expected behaviour. I was pretty sure it will not work.
If someone has any suggestions for a solution or a workaround, I'm a buyer.
What I've already tried so far :
Use simple quote
Remove the quotes right after $select=
Remove the subject part $select="Test 1", same behaviour as the first request mentioned in this post. It will looks for emails that contain "test" or "1".
Best regards.
EDIT :
After sasfrog's anwser :
I used $filter : It works well with simple operator AND, OR.I have some errors by using the Not Operator. And btw you have to use the orderby parameter to show the result by date and add the field in filter parameters.
Exemple 1 (working, what I asked for first) :
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc &$filter=receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')
Exemple 2 (not working)
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc &$filter=(receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')) NOT(contains(from/EmailAddress/address,[specific address]))
EDIT 2
After some test with the filter parameters.
The NOT operator is still not working so to workaround use "ne" (non-equals)
the example 2 becomes :
https://graph.microsoft.com/v1.0/me/messages/?$orderby=receivedDateTime desc&$filter=(receivedDateTime ge 1900-01-01T00:00:00Z AND contains(subject,'test 1')) AND (from/EmailAddress/address ne [specific address])
UPDATE : OTHER SOLUTION WITH $search
Using $filter is great but it looks like it was sometimes pretty slow. So I found a workaround aboutmy issue.
It's to use AND operator between all terms.
Exemple 4 :
I'm looking for the mails where the subject is test 1;
Let value = "test 1". So you have to splice it by using space separator. And after write some code to manipulate this array, to obtain something like below.
$search="(subject:test AND subject:1)"
The brackets can be important if you use a multiple fields search. And VoilĂ .
Not sure if it's sufficient for what you're doing, but how about using the contains function within a filter query instead:
https://graph.microsoft.com/v1.0/me/messages?$filter=contains(subject,'Test 1')
Sounds like you're already looking at the doco but here it is just in case.
Update also, this worked for me using the search method:
https://graph.microsoft.com/v1.0/me/messages?$search="subject:'Test 1'"

How to keep the upper case and lower case letters in a column alias in the results in Redshift

In Redshift we are trying to give more meaningful aliases to the columns we are returning from the queries as we are importing the results into TABLEAU, the issue is that RedShift turns all the letter to lower case ones, i.e. from "Event Date" it then returns "event date", any idea on how to work this one out to keep the alias given?
I know I'm a bit late to the party but for anyone else looking, you can enable case sensitivity, so if you want to return a column with camel casing for example
SET enable_case_sensitive_identifier TO true;
Then in your query wrap what you want to return the column as in double quotes
SELECT column AS "thisName"
Or as per OP's example
SELECT a.event_date AS "Event Date"
https://docs.aws.amazon.com/redshift/latest/dg/r_enable_case_sensitive_identifier.html
Edit: To have this behaviour as default for the cluster you will need to create/update a parameter group in Configurations => Workload Management. You can't change the settings for the default parameter group. Note, you will need to reboot the cluster after applying the parameter group for the changes to take effect.
No, you cannot do this in Redshift. all columns are lowercase only.
You can enforce upper case only by using
set describe_field_name_in_uppercase to on;
Also see the examples here https://docs.aws.amazon.com/redshift/latest/dg/r_names.html you can see that the upper case characters are returned as lower case. and it says "identifiers are case-insensitive and are folded to lowercase in the database"
You can of course rename the column to include uppercase within Tableau.
I was going through AWS docs for redshift and looks like INTCAP function can solve your use case
For reference => https://docs.aws.amazon.com/redshift/latest/dg/r_INITCAP.html
Brief description (copied)
The INITCAP function makes the first letter of each word in a string uppercase, and any subsequent letters are made (or left) lowercase. Therefore, it is important to understand which characters (other than space characters) function as word separators. A word separator character is any non-alphanumeric character, including punctuation marks, symbols, and control characters. All of the following characters are word separators:
! " # $ % & ' ( ) * + , - . / : ; < = > ? # [ \ ] ^ _ ` { | } ~
And in your case you have declared field name as event_date which will convert to Event_Date.
And next you can use REPLACE function to replace underscore '_'
For reference => https://docs.aws.amazon.com/redshift/latest/dg/r_REPLACE.html
You need to put
set describe_field_name_in_uppercase to on;
in your Tableau's Initial SQL.

Crystal Reports - Remove Carriage Returns

I am writing a report for my company right now and am running into issues with one data set in particular. Our accounting team puts unnecessary (as I see it) carriage returns when typing in data in one of our MISC_COMMENT fields.
Example data:
2 Returns
For warping
Cost = $1
RGA# 123
This comes out on the report as such... The report requester has asked that the data be as follows:
2 Returns For Warping Cost = $1 RGA 123
Is there anyway to strip out the carriage returns? Data will vary in characters and length. Not sure if a substring is still applicable then?
Thanks for the help!
Use the replace function to replace one or both of Chr(10) and Chr(13) depending on whether one or both exist inside your text.
Replace(Replace(MISC_COMMENT, Chr(13), " "), Chr(10), " ")

How to escape quotation marks in Enterprise Architect Code Generation Template

I want to give enumeration values a further description. Therefore I'm adding a custom Tagged Value to the attributes of the enumeration called Description, if a description shall be provided. The goal is, to add a custom C# attribute to the tagged enumeration attribute during code generation, but only if such a Tagged Value exists. Therefore I need to edit the code generation template for Attribute Declaration. Currently it works using:
$hasDescription = %attTag:"Description" ? "true" : "false"%
%if $hasDescription == "true"%
[Description(%qt%%attTag:"Description"%%qt%)]
%endIf%
which gives me the desired output. But if there are quotation marks in the value, it breaks the output code file. It won't compile. Therefore I need to replace/escape all quotation marks in the value field of the Tagged Value. I tried the following (in various combinations):
%REPLACE(attTag:"Description", "\"", "\\\"")%
%REPLACE(attTag:"Description", """", "\\""")%
%REPLACE(attTag:"Description", "%qt%", "%sl%%qt%")%
%REPLACE(attTag:"Description", %qt%, %sl%%qt%)%
Note: %qt% is used to insert ", %sl% is used to insert \ (reference)
None of them works. Either the string as it is will be inserted into the generated code file or nothing happens to the quotation marks in the value of Tagged Value.
So is there a way to escape those characters to be able to replace them in a string within a Code Template?
Using Enterprise Architect 13.5.1351
Question asked first on SE Software Engineering
I looked through the other templates provided and finally found the solution after some more fiddling. The macro take either some text in quotation marks or variables as parameters. Since using the escape sequences directly in the REPLACE macro didn't work, I tried assigning them to variables beforehand:
$qt = %qt%
$escape = %sl% + %qt%
$description = %REPLACE(attTag:"Description", $qt, $escape)%
That's it. Finally works. It is important to add the + between %sl% and %qt% on the second line, even though the documentation on Code Template Syntax > Literal Text states it otherwise. $escape = %sl%%qt% does not work, as it yields me just a \ without the ".
The variable $description is not necessary, but added for readability.

How to replace similar code in VS 2017.

I am replacing our logging functionality and it is taking a long time to manually go through all of the code and replace it.
Here is the current code:
Error Messages:
cLogger.LogMessage(ComponentID.ClientID, CLASS_NAME, "AddContextMenuItem", MessageType.mtErrorMessage, "Null MenuItem provided. MenuItem's status not changed");
cLogger.LogMessage(ComponentID.ClientID, CLASS_NAME, "enableDisableToolbarItem", MessageType.mtErrorMessage, "Invalid toolbaritem provided.");
Exceptions:
cLogger.LogMessage(ComponentID.ClientID, CLASS_NAME, "enableDisableContextMenuItem", MessageType.mtException, ex);
cLogger.LogMessage(ComponentID.ClientID, CLASS_NAME, "AddToolbarItem", MessageType.mtException, exc);
Is there a simple way to create a macro (never used a macro before) or power shell or notepad++ script or something else to find and replace all of these different instances so that they look like the following:
New Error Messages:
logger.Log(LogLevel.Error, CLASS_NAME + " AddContextMenuItem - Null MenuItem provided. MenuItem's status not changed");
logger.Log(LogLevel.Error, CLASS_NAME + " enableDisableToolbarItem - Invalid toolbaritem provided.");
and
New Exceptions:
logger.Log(LogLevel.Exception, CLASS_NAME + " enableDisableContextMenuItem - " + ex);
logger.Log(LogLevel.Exception, CLASS_NAME + " AddToolbarItem - " + exc);
I am replacing the code in the entire project and it will just simply take way too long to go through and manually change all of the logging code manually. Any help is greatly appreciated.
There are a few options:
Regex Search & Replace in Visual Studio:
search for the exception example
\w+logger.LogMessage\([^,]+,([^,]+),([^,]+),[^,]+,([^\",]+)\);
replace
logger.Log(LogLevel.Exception, $1 + $2 + $3);
Use Resharper structural Search & Replace
Build a CodeFix for Roslyn
Yes, you can likely do this with a Regular Expression, easier in PowerShell perhaps than in Notepad++ or perhaps VSCode.
It's difficult to tell from your examples precisely what you are changing in each item, but the basic concept is to do the following:
Match the static text that establishes the type of item to change
Also match the variable text with wildcards (.* etc) enclosed in CAPTURING parentheses
Replace with new static text and 'rearranged' variable text using the $1, $2, etc backreferences to the capture groups (or $Matches[1] etc.)
If #3 is more complicated, you'll need to further alter the variable text before replacing -- this is where a script language has an advantage over a pure search and replace.
Here is a simplified example (PowerShell but similar in other langauges or editors that support Regexes) for statically replacing the "FunctionOldName" while swapping the order of Param1 and Param2 and altering the names based on the original names for these params:
"Function_OldName Param1 Param2" -replace 'Function_OldName\s+(\w+)\s+(\w+)',
'NewFunctionName New$2Parm New$1Parm'
The $1 and $2 are backreferences to the "1st parens" and "2nd parens" respectively in the match string.
If you can write out clear examples showing which parts of your changed text must be matched, simply altered, rearranged, or rebuilt then it might be possible to show you some more relevant examples....
You can do this across many files with either PowerShell or the editors, but generally doing it to many files is again a bit easier in a Programming language (e.g., PowerShell.)
Get-ChildItem *.PS1 -recurse | ForEach-Object {
'Function_OldName\s+(\w+)\s+(\w+)', # your match goes here
'NewFunctionName New$2Parm New$1Parm' # your replacement goes here
}