Get second letter in expression in SSRS - reporting-services

I have a list of machines listed like so:
M101
M102
M201
M202
M203
What I desire to return is
1
1
2
2
2
My question is how would I extract my desired return of the second charcter from my group expression? My field is =Fields!machine.Value

I would use the following
=MID(Fields!machine.Value,2,1)
That will give you the second charcter in the string.

Related

How to split single column data into multiple columns in ssrs reports?

I have one table as shown in bellow
EmpID Name
1 Ram,Shaker,Sarath
2 Raju,Ravi
I need output as
EmpID Name Name
1 Ram Shaker,Sarath
2 Raju Ravi
For the first column, you can use the Split function and take the first element:
=IIf(
Split(Fields!myColumn.Value, ",").Length > 1,
Split(Fields!myColumn.Value, ",").GetValue(0),
Fields!myColumn.Value
)
For the second column, you can use the Right function to grab the remaining characters:
=IIf(
Split(Fields!myColumn.Value, ",").Length > 1,
Right(
Fields!myColumn.Value,
LEN(Fields!myColumn.Value) - LEN(Split(Fields!myColumn.Value, ",").GetValue(0)) - 1
),
""
)
The LEN() function is for BIDS. Use LENGTH() instead if you're in Report Builder.
I agree with the comment from #pedram, but assuming you go down the path of a report, I would be using the InStr function with the Left Function
so you have something like the following function in a column/cell of a table
=Left(Name, InStr(Name, ","))
The InStr function finds the first instance of the comma and reports is position to the Left function
Now this assumes that the the comma is the delimiter.

MYSQL - Find rows, where part of search string matches part of value in column

I wasn't able to find this anywhere, here's my problem:
I have a string like '1 2 3 4 5' and then I have a mysql table that has a column, let's call it numbers, that look like this:
numbers
1 2 6 8 9 14
3
1 5 3 6 9
7 8 9 23 44
10
I am trying to find the easiest way (hopefully in a single query) to find the rows, where any of the numbers in my search string (1 or 2 or 3 or 4 or 5) is contained in the numbers column. In the give example I am looking for rows with 1,2 and 3 (since they share numbers with my search string).
I am trying to do this with a single query and no loops.
Thanks!
The best solution would be to get rid of the column containing a list of values, and use a schema where each value is in its own row. Then you can use WHERE number IN (1, 2, 3, 4, 5) and join this with the table containing the rest of the data.
But if you can't change the schema, you can use a regular expression.
SELECT *
FROM yourTable
WHERE numbers REGEXP '[[:<:]](1|2|3|4|5)[[:<:]]'
[[:<:]] and [[:<:]] match the beginning and end of words.
Note that this type of search will be very slow if the table is large, because it's not feasible to index it.
Here is a start point (split string function) : http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/ := SplitString(string,delimiter,position)
Create a function so it converts a string to an array := stringSplitted(string,delimiter)
Create a function so it compares two arrays :=arrayIntersect(array1, array2)
SELECT numbers
FROM table
WHERE arrayIntersect(#argument, numbers)
Two function definitions with loops and one single query without any loop
SELECT * FROM MyTable WHERE (numbers LIKE '%1%' OR numbers LIKE '%2%')
or you can also use REGEX something like this
SELECT * FROM events WHERE id REGEXP '5587$'

Lookupset function in ssrs returning strange error

I am trying to use the lookupset function in ssrs and I keep getting this error:
[rsLookupOfInvalidExpressionDataType] The Value expression for the textrun ‘Textbox46.Paragraphs[0].TextRuns[0]’ uses a lookup function with an expression that returned a data type that is not valid for the lookup function. The data type must be an RDL Variant type.
My first dataset looks like this:
Student Name | PID
Anakin SkyWalker | 1
Obi-Wan Kenobi | 2
And my second dataset (named Awards) looks like this:
PID | Xtrnl_Award_Type
2 | BA
The expression I'm using is:
=Join(LookupSet(Fields!PID.Value, Fields!PID.Value, Fields!Xtrnl_Award_Type_Code, "Awards"), ",")
If the person doesn't have an entry in the second dataset, things are fine. But if they do, my column just shows #Error instead a comma separated list of awards. The field in question is a varchar, if that helps or not. I don't understand why I'm getting an error or how I can see just what the expression is returning. Can anyone help?
Looks like you missed a bit on the third parameter for the LookupSet function:
Instead of
=Join(
LookupSet(
Fields!PID.Value,
Fields!PID.Value,
Fields!Xtrnl_Award_Type_Code,
"Awards"),
",")
Try this:
=Join(
LookupSet(
Fields!PID.Value,
Fields!PID.Value,
Fields!Xtrnl_Award_Type_Code.Value,
"Awards"),
",")
(Actually, even then, the field name doesn't match what you show in your sample. You may need to change the parameter to Fields!Xtrnl_Award_Type.Value

MySQL: Select values containing only one digit

Let's say I have a column with emails:
test1#test.com
test2#test.com
test3test#tes.com
test123#test.com
test321#test.com
test23test.com
How can I select only those that contains only one digit?
Result should be:
test1#test.com
test2#test.com
test3test#tes.com
I tried:
REGEXP '[[:digit:]]{1}' and REGEXP '[0-9]{1}' but it shows all results that contain AT LEAST one digit
try to use ^[^0-9]*[0-9]{1}[^0-9]*$
If you don't specify number of repetitions, it is one copy by default.
Try something like
REGEXP '(^[0-9]+)([0-9])#.+'

using regualr expression in mysql to select specific rows

I'm trying to select a small set of records that match a patten I have a series of numbers in each row such as
1
2
3
some of them have sub numbers
3.1
3.2
4
5
I can select only the whole numbers using
REGEXP '^[0-9]+$'
I can select all rows that have a . in them like 3.1 3.2 etc using
REGEXP '[.]{1}'
but I can't seem to select for example only sub numbers that start with 3 I've tried
REGEXP '[^3.]{1,}'
but that returns all records
Ideally I want to return only records that are in the format of 3.1 I would like to define the start number and the dot so 3. then the second part match against the records
I hope this makes sense
I used '3\.[0-9]{1,}' - it matched.
Yours probably fails because of unescaped dot - ., which matches every character.
Escape characters with \
Format 3.d where d is digit:
3\\.[0-9]