Make a People Chart - reporting-services

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

Related

Getting the wrong answer when getting the sum of column name

I have a problem in getting the sum of one of my column names in database (PRICE). If I insert 1000.00 and 3600.00 to get the sum of them, I am getting 4.00 instead of 4600.00. But when the total is below 1000 I get the correct answer.
It appears that your price_per_case column is char or varchar column rather than a numeric column such as decimal(10,2). So, it is converting the column to double but ignoring everything after the , character (and probably issuing warnings during the conversion). You can verify this by trying the following:
select '1,234' + '3,456';
You will end up with 4;
You should try running:
update ordered set price_per_case = replace(price_per_case, ',', ''); /* get rid of commas */
Then you should change the type of this column to decimal(10,2) or some appropriate precision.
Maybe the machine when you are programming have different “Locale” of MySql Server (are both in the same machine)?
In this case also format currency/double/decimal is different.
To avoid that you need to change Locale in you .NET method/sub/function before/into you get query result
Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("it-IT")
Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("it-IT")
or change Locale in MySql
SET lc_time_names = 'it_IT'; Here continue your query
In this example I have used Italian Locale

Is there a way to search sensory data stored in MySQL?

I have a table where I have multiple of columns with sensory data such as the temperature. I wanted to ask if there's an existing way to search for the data available in the table using a search bar that inputs the user's query (edit: this basically mean that the user can input any textual query, but how can the query be translated to something useful in a table full of sensory data?) I have already done my research but I couldn't find any decent results. Bellow is the description of the table:
As you can see, this table mainly have numerical values, except for the names of the columns and the Client and datetime columns.
Yes there are multiple ways.
You could prompt the user to specify different criteria for the search, for example:
DateRange
Client
TempRange
Status
And many more, this way you can filter the data to get only what you are looking for; but from what I can understand in your question is that you want a single search box with a single input to search in multiple fields, if that is the case you will need to filter on each one of the fields you are interested in, using the OR operator and some data type conversion.
--your parameters and temporary variables to perform conversion
DECLARE #criteria VARCHAR(20) = '55';
DECLARE #criteria_temp INT = 0;
--try conversions here
BEGIN TRY
SET #criteria_temp = CONVERT(int,#criteria,0);
END TRY
BEGIN CATCH
SET #criteria_temp = 0;
END CATCH
--your query
SELECT * FROM MyTable
WHERE
Client LIKE '%'+#criteria+'%' OR
TEMP = #criteria_temp
You can see that this query will retrieve all the record where Client contains '55' and records where the TEMP is equal to 55.
If the user inputs the string 'test' as the criteria the conversion for #criteria_temp will fail, int this case you can use a default value, for example 0 and the query will return all records where Client contains 'test' and records where temp is equal to 0.
Based on this you can add more variables for different datatypes and search conditions in the query.

Create Function Date

I'm attempting to create a function with 2 params.
1st param is the date
2nd is an int
What i want the function to do:
Function('2014-04-20', 5) results in '2013-11-20'
Function('2013-11-10', 2) results in '2013-09-10'
CREATE FUNCTION MonthDiff(
#in_date DATE
,#in_mn_adjust INT)
RETURNS DATE
AS
BEGIN
DECLARE #in_new DATE;
SET #in_new = DATEADD(MM, -#in_mn_adjust, #in_date);
RETURN #in_new;
END;
I ran 'select dbo.monthdifference('2014-04-22', 3). The error that I got is Conversion failed when converting date and/or time from character string.
What am I doing wrong?
Use below code to solve your problem.
Declare #str Varchar(10)
Declare #result Varchar(10)
set #str= '2012/10/23'
set #result = DATEADD(MONTH,-2,CONVERT(date,#str,102))
Sometimes SQL Server does silly things and misinterprets some date strings1. The following formats are always safe. I believe there are some other formats that are also safe when dealing with the newer date, time and datetime2 types but I tend to play it safe:
YYYYMMDD
YYYY-MM-DD'T'hh:mm:ss
YYYY-MM-DD'T'hh:mm:ss.mil
So try:
select dbo.monthdifference('20140422', 3)
(The 'T' in my example formats is the literal character T, being used as a separator, instead of a space, and instead of the other characters in those format strings which are placeholders, so e.g. 2014-04-24T09:23:00 is in one of my listed safe formats)
1For example, if your language settings are British it interprets nnnn-nn-nn, where all ns are digits, as a YYYY-DD-MM format - despite the fact that I doubt that anyone in Britain would attempt such an interpretation.

Converting a upper case database to proper case

I am new to SQL and I have several large database with upper case first and last names that I need to convert to proper case in SQL sever 2008.
I am using the following to do this:
update database
Set FirstNames = upper(substring(FirstNames, 1, 1))
+ lower(substring(FirstNames, 2, (len(FirstNames) - 1) ))
I was wondering if there was any way to adapt this so that a field with two first names is also updated (currently I make the change and then go through and manually change the second name).
I have looked over the other answers in this field and they all seem quit long, compared to the query above.
Also is there any way to assist with converting the Mc suranmes ( I will manually change the others)? MCDONALD to McDonald, again I am just using the about query but replacing the FirstNames with LastName.
This is probably best done outside of SQL. However, if there is a requirement to do it on the server or if speed isn't an issue (because it will be an issue so you need to figure out if you care), the way you are going about it is probably the best way of doing so. If you want, you could create a UDF that puts all of the logic in one area.
Here is some code I came across (with attribution and more information below it):
CREATE FUNCTION dbo.fCapFirst(#input NVARCHAR(4000)) RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE #position INT
WHILE IsNull(#position,Len(#input)) > 1
SELECT #input = Stuff(#input,IsNull(#position,1),1,upper(substring(#input,IsNull(#position,1),1))),
#position = charindex(' ',#input,IsNull(#position,1)) + 1
RETURN (#input)
END
--Call it like so
select dbo.fCapFirst(Lower(Column)) From MyTable
I got this code from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=37760 There is more information and other suggestions in this forum as well.
As for dealing with cases like the McDonald, I would suggest one of two ways to handle this. One would be to put a search in the above UDF for key names ('McDonald', 'McGrew', etc.) or for patterns (the first two letters are Mc then make the next one capital, etc.) The second way would be to put these cases (the full names) in a table and have their replacement value in a second column. Then simply do a replace. Most likely, however, it will be easiest to identify rules like Mc then capitalize instead of trying to list every last-name possibility.
Don't forget you may want to modify the above UDF to include dashes, not just spaces.
Maybe this is too long but it is very easy and can be adapted for -, ', etc:
UPDATE tbl SET LastName = Case when (CharIndex(' ',lastname,1)<>0) then (Upper(Substring(lastname,1,1))+Lower(Substring(lastname,2,CharIndex(' ',lastname,1)-1)))+
(Upper(Substring(lastname,CharIndex(' ',lastname,1)+1,1))+
Lower(Substring(lastname,CharIndex(' ',lastname,1)+2,Len(lastname)-(CharIndex(' ',lastname,1)-1))))
else (Upper(Substring(lastname,1,1))+Lower(Substring(lastname,2,Len(lastname)-1))) end,
FirstName = Case when (CharIndex(' ',firstname,1)<>0) then (Upper(Substring(firstname,1,1))+Lower(Substring(firstname,2,CharIndex(' ',firstname,1)-1)))+
(Upper(Substring(firstname,CharIndex(' ',firstname,1)+1,1))+
Lower(Substring(firstname,CharIndex(' ',firstname,1)+2,Len(firstname)-(CharIndex(' ',firstname,1)-1))))
else (Upper(Substring(firstname,1,1))+Lower(Substring(firstname,2,Len(firstname)-1))) end;
Tony Rogerson has code that deals with:
double barrelled names eg Arthur Bentley-Smythe
Control characters
I haven't used it myself though...

How can I enter values to varchar(max) columns

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+.