Remove first and last characters - reporting-services

A Field gives me the following string:
#$Mercury#$Venus#$Earth#$Mars#$
My goal is to remove the #$-chars and separate the text with comma and space. It should look like this:
Mercury, Venus, Earth, Mars
What I tried to do:
Remove the #$-chars at start and end;
Replace the remaining #$-chars with ", "
My code:
=Replace(
Left(
Right(
First(Fields!FieldX.Value, "DATASET"), Len(First(Fields!FieldX.Value, "DATASET"))-2),
Len(First(Fields!FieldX.Value, "DATASET"))-2),
"#$",", "
)
This gives me:
Mercury, Venus, Earth, Mars,
At the end after Mars there is a comma and it shouldn't be there. I don't know how to do that. Maybe the MID function is the better solution, but then I don't understand how it can be used when the strings are of variable length.
Thanks in advance.

This should work. I tested in a table so you will have to add the FIRST and "DATASET" bits back in )
=JOIN(
SPLIT(MID(Fields!SampleText.Value, 3, LEN(Fields!SampleText.Value)-4), "#$"),
",")
All we do here is chop off the first and last 2 characters, then SPLIT on each instance of #S which gives us an array. Then JOIN the array elements back togther using , as the delimiter.

Related

I don't know how to find .exe with numbers in MYSQL

For example, I would like to find an 'exe' with a fixed path: \Temp\3038.exe
The number before '.exe' is fixed to 4 digits, but the value is random(0001 ~ 9999).
Only numbers are changed to 4 random digits.
I'd really appreciate it if you could tell me what to do.
I tried 2ways:
SELECT * FROM myTable WHERE path REGEXP '\\Temp\\\d{4}.exe';
SELECT * FROM myTable WHERE path like '\\Temp\\\d{4}.exe';
my data:
C:\\Users\\AppData\\Local\\Temp\\1536.exe
C:\\Users\\AppData\\Local\\Temp\\6247.exe
C:\\Users\\AppData\\Local\\Temp\\2508.exe
.......(skip)
For these I need to get 1536, 6247, 2508
DBFIDDLE
A regular expression will bite, especially if it has a '` in it.
When you say the data is: C:\\Users\\AppData\\Local\\Temp\\2508.exe will it have one '` or two '' ? to be honest i got a but lost too 😉
The DBFIDDLE uses:
select *
from mytable
where path REGEXP '.*\\\\Temp\\\\\\d{4}.exe';
The REGEXP looks complicated, but let me try to explain, it matches
.* a dot is any character, and an asterix says that character(s) can be present 0 or more times.
\\ a backslash
\\ another backslash
'Temp' the four letters 'T','e','m' and 'p', in this order.
\\ another backslash
\\ another backslash
\d{4} the \d is representing a digit (which is a number between 0 and 9), and the '{4}' will match four of those.
. this is a random character
exe this is the three letters in 'exe'.
A bug in this is that this will also match: C:\\Users\\AppData\\Local\\Temp\\2508Xexe
But, I like to keep room for improvements 😉😁
P.S. When replacing the '.' by '.' it will match a dot literally, and not a random charachter.
EDIT: re-reading the question, I see that you only want the numbers.
From the results you can take LEFT(RIGHT(path,8),4)
This will first take the last 8 charachters (RIGHT(path,8)), and from that the first 4 characters. This should work because the matching regular expression result always end in 4 numbers with '.exe' after it.

Combining Remove and Replace Function in MS SQL Report Builder

A field gives me the following string:
#$TEXTA#$TEXTB#$TEXTC
I want to remove the #$-chars and seperate the values by a new line. In addition I want to replace special characters (&). In the end it should look like this:
TEXTA
TEXTB
TEXTC
So I use this code:
=Replace(Replace(Fields!My_Field.Value,"&","&"),"#$",Environment.NewLine)
The string starts with #$, so this code makes a new line in the beginning, which I want to avoid by using this code:
=Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
I want to remove the first two chars before the replace function starts. My problem is, that I dont know how to combine these two functions to work properly.
Without testing this....
I think you should just be able to replace your reference to the field in your first expression, with your second expression, like this.
=Replace(
Replace(
Right(First(Fields!My_Field.Value, "DATASET"), Len(First(Fields!My_Field.Value, "DATASET"))-2)
,"&"
,"&"
),
"#$",
Environment.NewLine
)

SSIS Expression Builder - How to find last occurrence of a character

I have values that look like this:
D:\DM-250\Insert_Jobs-QA-UAT\14-FILE_A_UpdateInsert.dts
D:\DM-250\Insert_Jobs-QA-UAT\Something_DaisyChain\14-stuff_and_things_UpdateInsert.dts
D:\DM-250\14-another_file.dts
I want the very ends of these 3 values, starting from the last "\" character.
I tried to use FINDSTRING, but I don't know how to grab the last occurrence of a character.
Any suggestions?
This will give you the position from the right.
findstring(reverse([your column]),"\",1)
I am guessing you are trying to extract filename which is:
right([your column], [result from above] - 1)

How to replace delimiters from a string in SQL Server

I have the following data
abc
pqr
xyz,
jkl mno
This is one string separated by delimiters like space, new line, comma, tab.
There could be two or more consecutive spaces or tabs or any delimiter after or before a word.
I would like to be able to do the following
Get the individual words removing all leading and trailing delimiters off it
Append the individual words with "OR"
I am trying to achieve this to build a T-SQL query separated by OR clause.
Thanks
I think you can achieve what you need (although I think using a programming language is way better) using just SQL, here is my approach.
Kindly note that I will just handle commas, newlines and multiple-spaces, but you can simple follow using the same technique to remove the rest of your undesired characters
so let's assume that we have a table names ExampleData with a column named DataBefore and another called DataAfter.
DataBefore: has the line value that you want to clean
DataAfter: will host the cleaned text
First we need to trim the preceding & leading space(s) from the text
Update ExampleData
set DataAfter = LTRIM(RTRIM(DataBefore))
Second, we should clean all the commas, and replace them with spaces (doesn't matter if we will end up with many spaces together)
Update ExampleData
set DataAfter = replace(replace(DataAfter,',',' '),char(13),' ')
This is the part in which you may continue and remove any other characters using the same technique, and replace it by a space
So far we have a text that has no spaces before or after, and every comma, newline, TAB, dash, etc character replaced by a space, let's continue our cleaning procedure.
We can now safely move on to replace the spaces between words with just one, this is made by using the following SQL statement:
Update ExampleData
set DataAfter = replace(replace(replace(DataAfter,' ','<>'),'><',''),'<>',' ')
as per your needs, we need to place an OR between each word, this is achievable with this SQL statement:
Update ExampleData
set DataAfter = replace(replace(replace(DataAfter,' ','<>'),'><',''),'<>',' OR ')
we are done now, as a final step that may or may not make a change, we need to remove any space at the end of the whole text, just in case an unwanted character was at the end of the text and as a result got replaced by a space, this can be achieved by the following statement:
Update ExampleData
set DataAfter = RTRIM(DataAfter)
we are now done. :)
as a test, I've generated the following text inside the DataBefore column:
this is just a, test, to be sure, that everything is, working, great .
and after running the previous commands, ended up with this value inside the DataAfter column:
this OR is OR just OR a OR test OR to OR be OR sure OR that OR everything OR is OR working OR great OR .
Hope that this is what you want, let me know if you need any extra help :)

Are there markers for the start and end of a string in MySQL?

Basically I'm trying to remove a value (val2 for example) from a string that looks like 'val1,val2,val3'. However the values can be arranged in any order and I want to avoid ending up with stuff like ',val1,val3', 'val1,,val3' or 'val1,val3,'. I thought about replacing 'val2' with '' and then replacing ',,', ',end' and 'start,' with ','. But I don't know what the markers for end and start of a string are.
Storing multiple values in one single column is never a good idea. You should think about redesign your data model.
You can get what you want with regular expressions, see MYSQL documentation. There are two characters ^ and $ that match beginning and end of a string.