I have column with values like:
Test
test 1
test 2
test 3
test 4
I am trying to put the values in a report in Microsoft Report Builder, but I don't want it listed in a table. I would like it to be listed like below in a text box:
test 1, test 2, test 3, test 4
Is there an expression I can use? I have looked and tried Join and Split but haven't gotten the results I am looking for.
You can do this quite easily using LOOKUPSET() to get the values into an array and then using JOIN() to combine them into a string.
=Join(LookupSet(1, 1, Fields!myTestCol.Value, "DataSet1"), ", ")
As we want all the rows from the dataset, I've used 1 in the first 2 arguments as a shortcut as 1 always equals 1 , every row in "DataSet1" will be returned. Then we JOIN() them with ", " as the separator.
Note: "DataSet1" is the case-sensitive name of your dataset. You need to change this to match your dataset name or scope name (i.e. a RowGroup name) as required.
Related
In my placeholder expression, I looking to pull multiple values from a dataset variable which relate to the parameter multiple selected values. My parameter labels are locations (Location 1, Location 2, Location 3, etc...) and the parameter values are IDs (ID1, ID2, ID3, etc...). In my dataset, I have abbreviated versions of the locations which is what I want to display in my SSRS report (Loc 1, Loc 2, Loc 3).
I would like the values to be separated by a comma.
I know I can get the parameter labels with this code:
=Join(Parameters!ParameterName.Label, ",")
So I tried something similar such as:
=Join((Fields!ABBREV.Value, ", "), "Dataset1")
and
=Join((Fields!ABBREV.Value,"Dataset1"), ", "), )
but neither worked
In the end, I would like to see the list of abbreviated locations. For example, if the user selects Location 5, Location 7 and Location 9 in the parameter, my expression should show:
loc 5, loc 7, loc 9
What is the right expression for this? Thanks in advance.
EDIT SOLUTION:
This worked...
=JOIN(MULTILOOKUP(Parameters!ParameterName.Value, Fields!ID.Value, Fields!ABBREV.Value, "DataSet1"), ", ")
I think it will work if you use LOOKUPSET.
=JOIN(LOOKUPSET(1, 1, Fields!ABBREV.Value, "DataSet1"), ", ")
Using 1 for the LOOKUP fields will return all records in Dataset1.
I am trying to write a MySQL select statement where I am trying to select values based on the last letter or letters of a string. The problem is... these values have double letters at the end of the string and I am not able to differentiate between them when getting results.
For example... I have the following 2 values in a table
1. Mens 3's AA
2. Mens 3's A
The query I am currently using returns both values when I only want to return #2 above. Here is the query:
SELECT divisions.div_id, divisions.div_lname
FROM divisions
WHERE LEFT(divisions.div_lname,1) = "M"
AND divisions.div_lname LIKE '%3%'
AND RIGHT(divisions.div_lname,1) = 'A'
ORDER BY divisions.div_nop, divisions.div_order
I really need to understand the best approach for selecting 1 but not the other when I have values that contain duplicate letters at the end of the string. Is there a regex approach that would work?
try using SUBSTRING_INDEX() like this, it'll return the last chunk after the space..so it won't return rows that have 'AA'..and only return row with 'A'
SELECT divisions.div_id, divisions.div_lname
FROM divisions
WHERE LEFT(divisions.div_lname,1) = "M"
AND divisions.div_lname LIKE '%3%'
AND SUBSTRING_INDEX(divisions.div_lname,' ',-1) = 'A'
ORDER BY divisions.div_nop, divisions.div_order
one of my table contains column path stores the URL example:\xyz\attachments, \abc\attachments, etc total i have 16 combinations to replace
i found rows by using rlike in where clause 'abc|xyz|'
have to update xyz with xxx or abc with yyyy
i am not sure how to update these part of the values of column. Is it possible using single query or i have to write 16 queries to do that? please advise here
This is not reliable, but is doable. Basically nested replace() calls:
UPDATE ...
SET yourfield = REPLACE(REPLACE(yourfield, '\\xyz', 'newtext'), '\\abc', 'othertext')
Note that if xyz or abc can appear in multiple places in either string, you may end up replacing something that shouldn't have been.
If I have a database table that has one column that contains a regex pattern, is it possible to return rows (without systematically testing each row in turn) that a string matches?
for example, a table like this:
RowID RegExPattern
1 foo\.$
2 bar\.$
3 baz\.$
4 (foo|bar)\.$
and an input string like this:
foo.php
will return RowIDs 1 and 4
If I have a database table that has one column that contains a regex pattern, is it possible to return rows [...] that a string matches?
Yes, that's possible.
SELECT RowID
FROM yourtable
WHERE 'foo.php' REGEXP RegExPattern
Note though that your regular expressions won't match. If you omit the $ then they will.
See it working online: sqlfiddle
(without systematically testing each row in turn)
Err... no. You need to test each row.
Very simple
I have a column of string like that :
abc1
abc2
abc3
abc4
abc5
I need to remove 'abc' from this column and keep only the number on the right, so column would have only the number like :
1
2
3
4
5
I thought about smth like that but it doesn't work
update table2
-> set col1 = case when 'abc1' then 1
-> else end;
I know how to concat text, I don't know how to undo it... Help please ^^;
#McArthey already hinted at it, but this is easy to do when the "abc" is consistently "abc" (i.e. the length doesn't change.)
Amongst the various string functions is one in particular: RIGHT(). This allows you to select a fixed number of characters from a string. e.g.
SELECT RIGHT('abc3',1) -- Results in "3"
SELECT RIGHT('abc3',2) -- Results in "c3"
Coupled with the LENGTH() function, you can conclude the numbers are anything past the 3rd character. i.e.
SELECT RIGHT('abc3',LENGTH('abc3')-3) -- Results in "3"
Obviously I'm using hard strings ('abc3'), but these can easily be replaced with column names.
The caveat here is that these all are based on fixed length letter prefixes. The more variable (changing) the "abc" in your example is, the harder picking the numeric value out of the column becomes.
If these are single digit values you could use
select right(column,1) ...
You may also find the REGEXP docs useful if it is more complex.
If you are trying to modify the column you will have to take the values separately and then concatenate them back together. It's difficult to give a precise answer since I don't know what you're trying to accomplish but you could do something with SUBSTR to grab the separate values.
Get 'abc': SUBSTR(column, 1,3)
Get digits: SUBSTR(column, 4)