I am working on Microsoft Report Builder
I need to show in my report a set of data that comes in a text string separated by "," (comma)
I have a field where what I need to separate comes from like this:
data1, data2, data3
and I need to show them in the report like this (in the same column)
data1
data2
data3
I mean leave a line for each item in the split.
Split (Fields! Data.Value, ",") (0)
I have tried this, it only shows me the value of position 0.
Could it be done somehow? thanks!
You would be better off doing this in your dataset query. Assuming you are using SQL Server. then you can do the following.
You will need a string split function. If using SQL 2016 or later you can use the built-in function string_split(). If you are using an older version then there are plenty of examples of functions you can use. I can supply one if you can't find one.
If all your data comes in a single row then you can do something like this, replacing the #string with your table column.
declare #string varchar(max) = 'Data1, Data2, Data3'
select result = ltrim(rtrim(value)) from string_split(#string,',')
This will give the following results
If you have data on several rows then you can do a similar thing but use CROSS APPLY to repeat the function for each row.
Here's an example
declare #t table (string varchar(max))
insert into #t VALUES
('Data1, Data2, Data3'),
('DataA, DataB, DataC')
select result = ltrim(rtrim(x.value)) from #t
cross apply string_split(string,',') as x
which gives the following result
Related
I am using a MySql stored procedure, get_list, to populate a ttk.Combobox
my_number = tk.StringVar()
cb=ttk.Combobox(top_frame,width=25,textvariable=my_number)
cb['values']=db.get_list()
cb.grid(row=1,column=4)
It works fine, except the results are bracketed by {}.
RESULTS: {Smith, John}
What I want: Smith, John
How do I get rid of the beginning and ending {}?
The problem is that the database query is returning a list of rows, where each row is a list with a single column. What you need for the values option is a list of strings.
So, the simple solution is to use a list comprehension to convert each row to a string. Something like this should work:
values = [row[0] for row in db.get_list()]
cb['values'] = values
Since I can't run your code I can't say for sure. Regardless, the root of the problem is that you're passing a list of lists (or tuples) and tkinter requires a list of strings.
Because internally tkinter uses curly braces for lists, it's adding the curly braces to preserve the nature of the data you're passing in. It's up to you to convert the data you get back from db.get_list() into a list of strings.
Bryan, I inserted the two line of code you suggested, but I am still getting value surrounded by {}. Lots I don't understand, but I believe, never know for sure, that the MySql procedure is returning a string. Here is the MySQL code:
CREATE DEFINER=`root`#`localhost` PROCEDURE `get_list`()
BEGIN
SELECT concat(last_name,', ', first_name) as last_first
FROM volunteers
ORDER BY
last_first;
END
my_number = tk.StringVar()
cb = ttk.Combobox(top_frame, width=25, textvariable=my_number)
values = [row[0] for row in db.get_list()]
cb['values'] = db.get_list()
cb.grid(row=1, column=4)
thanks for your persistence.
I want to create a visual count of people using a person icon to represent a number of people - like this:
Is there a way to do this in SSRS? I was also hoping to have a quarter/half/three-quarters of a person when necessary.
I don't believe it is possible to do this through SSRS on it's own no. There isn't support (as far as I'm aware) for duplicating images in this way based on a value.
An alternative (assuming you have access to the background query) would be to use something like Wingdings (yes it does have a use!)
My thought would be if you could get the query to return a string with the number of characters that you wish to display, you could then format this in SSRS to show a number of images related to this.
For example
--Assuming noOfDeaths is a field in table myTable
DECLARE #LoopCount INT
DECLARE #LoopTotal INT
DECLARE #NoOfDeathsIcon VARCHAR(1000)
SET #LoopCount = 0
SET #LoopTotal = (SELECT MAX(noOfDeaths) FROM myTable)
SET #NoOfDeathsIcon = ''
WHILE (#LoopCount < #LoopTotal)
BEGIN
SET #NoOfDeathsIcon = #NoOfDeathsIcon + 'N' -- 'N' is equal to the poison sign in Wingdings
SELECT #LoopCount = #LoopCount + 1
END
INSERT INTO myTable(noOfDeathIcon)
VALUES (#NoOfDeathsIcon)
--Inserts 'NNNNNNNN' into the field noOfDeathIcon
You could then configure the SSRS report to take this field and format it as Wingdings to get the following result
Note this solution only works for a single line, but I'm sure a Common table Expression could be used to iterate over a number of lines to generate the strings.
For reference, the Windings character sets are displayed here
I'm just starting developing reports in SSRS and would appreciate some help with this issue if possible! I'm selecting a dataset from a Dynamics database and want to then pass them to a SQL Server stored procedure referenced in another dataset to retrieve data from another database. I have created a report parameter and set it to Allow multiple values and to retrieve its values from a query and set it to the field that I want to retrieve.
The dataset would look like this:
U1234
U5678
U6789
In the dataset that uses the stored procedure I have set up a parameter, #pnum, and in the Parameter Value field I have created an expression using the Join statement like this:
Join(Parameters!pnum.Value, ", ")
When this gets passed to the stored proc it seems to be passing a string formatted like this:
'U1234, U5678, U6789'
Whereas what I would like to achieve is this:
'U1234', 'U5678', 'U6789'
so that I can use them in an IN statement. Is there a way of doing this within SSRS?
Many Thanks!
To anyone else experiencing this issue, the assumption made in the question on how the values are passed to the stored procedure and how they can be used are incorrect.
The value passed from the join expression would be formatted as such, without single quotes at the start and end:
U1234, U5678, U6789
Further to this, when passed to a stored procedure as a single string this can only be used as an in list by using dynamic SQL.
To parse out and filter on the passed values, the string will need to be split on the delimiter and inserted into a table (temporary or otherwise) to be joined to.
A suitable splitting can be found here (though others exist that may better suit your needs) utilising logic as follows:
declare #xml as xml,#str as varchar(100),#delimiter as varchar(10)
set #str='A,B,C,D,E'
set #delimiter =','
set #xml = cast(('<X>'+replace(#str,#delimiter ,'</X><X>')+'</X>') as xml)
select N.value('.', 'varchar(10)') as value from #xml.nodes('X') as T(N)
If you don't have to pass the values to a stored procedure and are using hardcoded datasets (Shared or not) you can actually directly use the parameter value without additional processing either in the query or by adding a join expression to the parameter value in the report:
select cols
from tables
where cols in(#MultiValueParameterName)
You have to add an extra field with the value wrapped in quotes.
Like this:
SELECT field1 AS display, '''' + field1 + '''' AS value
I have a report where the WHERE clause is determined by a parameter #param.
SELECT SOMESTUFF
FROM SOMETABLE
WHERE thing = #param
I've added values to the parameter so at runtime, the user decides what to run the report for from a drop down box. I want to make an option to run it for all the values I defined as well. I haven't been able to figure out the code to make this happen.
So if I've given values A, B, C to the parameter, how do I tell it to do all of them in the expression?
This really depends on the nature of the query, datatypes etc.
Assuming the 'thing' in your example is a int and your parameters are a comma separated list of int values you could use an IN clause in your query.
SELECT SOMESTUFF FROM SOMETABLE WHERE thing IN (#param)
Though in reality this would need to be an expression in SSRS
="SELECT SOMESTUFF FROM SOMETABLE WHERE THING IN (" + #param.Value + ")"
Seems from your example they may be strings (A,B,C) in which case you would need to put a single quote around each for this to work.
Using SQL-Server 2008 and concatenating string literals to more than 8000 characters by obvious modification of the following script, I always get the result 8000. Is there a way to tag string literals as varchar(max)?
DECLARE #t TABLE (test varchar(max));
INSERT INTO #t VALUES ( '0123456789012345678901234567890123456789'
+ '0123456789012345678901234567890123456789'
+ '... and 200 times the previous line'
);
select datalength(test) from #t
I used the following code on SQL Server 2008
CREATE TABLE [dbo].[Table_1](
[first] [int] IDENTITY(1,1) NOT NULL,
[third] [varchar](max) NOT NULL
) ON [PRIMARY]
END
GO
declare #maxVarchar varchar(max)
set #maxVarchar = (REPLICATE('x', 7199))
set #maxVarchar = #maxVarchar+(REPLICATE('x', 7199))
select LEN(#maxVarchar)
insert table_1( third)
values (#maxVarchar)
select LEN(third), SUBSTRING (REVERSE(third),1,1) from table_1
The value you are inserting in your example is being stored temporally as a varchar(8000) because. To make the insert one will need to use a variable which is varchar(max) and append to it to overcome the internal 8000 limit.
Try casting your value being inserted as a varchar(max):
INSERT INTO #t VALUES (CAST('0123456789012345678901234567890123456789'
+ '0123456789012345678901234567890123456789'
+ '... and 200 times the previous line' AS varchar(max)
);
Also, you may have to concatenate several <8000 length strings (each casted as varchar(max)).
See this MSDN Forum Post.
When I posted the question, I was convinced that there are some limitations for the length or maximal line width of a single string literal to be used in INSERT and UPDATE statement.
This assumption is wrong.
I was led to this impression by the fact the SSMS limits output width for a single column in text mode to 8192 characters and output of PRINT statements to 8000 characters.
Fact is, as far as I know you need only enclose the string with apostrophes and double all embedded apostrophes. I found no restrictions concerning width or total length of a string.
For the opposite task, to convert such strings back from database back to script the best tool I found is ssms toolspack which works for SQL-Server 2005+.