truncated incorrect INTEGER VALUE : 'EN_US' - mysql

got this error when I tried to create a table 'top20bypopulation' from a select statement
query :
CREATE table top20bypopulation as
SELECT Name,format(Population,'EN_US') as population FROM country
ORDER BY Population DESC
LIMIT 20;
error :
truncated incorrect INTEGER VALUE : 'EN_US'
But the SELECT runs okey, but when I create table out of it, it gives this error.
I am new to this language, someone please answer how to achieve this.

in your country table Population column is integer and you are trying to get format value
so when we pass two parameter then first one is value and second parameter must be precisioin
if you want to pass locale as parameter then format method be like
format(Population,2,'EN_US')

Related

The Value expression for the textrun ‘Textbox15.Paragraphs[0].TextRuns[0]’ contains an error: [BC30201] Expression expected

I received this error when I am trying to run a select statement in a text box in SSRS. So, basically, I am trying to return a field which is not in the given dataset. So I have run a subquery which returns the value using the existing dataset as a container.
But I don't know how to represent that return value in the Expression field. Because the expression field returns a value which is within the dataset provided.
I have provided the SQL that I have written.
Any suggestions would be much appreciated.
My intention is to return the "CommentText" value. However, the dataset does not contain any commenttext field, but an EmpID field. So I have created the subquery below that brings up the CommentText from LaborDtlComment table and when it matches with the EmpID in the report dataset it returns the CommentText Value.
select [CommentReturnQuery].[LaborDtlComment_CommentText] as [LaborDtlComment_CommentText],
[EmpBasic].[EmpID] as [EmpBasic_EmpID]
from Erp.EmpBasic as EmpBasic
inner join (select [LaborDtlComment].[CommentText] as [LaborDtlComment_CommentText],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum]
from Erp.LaborDtlComment as LaborDtlComment
inner join Erp.LaborDtl as LaborDtl on LaborDtlComment.Company = LaborDtl.Company
and LaborDtlComment.LaborHedSeq = LaborDtl.LaborHedSeq
and LaborDtlComment.LaborDtlSeq = LaborDtl.LaborDtlSeq) as CommentReturnQuery
on EmpBasic.EmpID = CommentReturnQuery.LaborDtl_EmployeeNum
My aim is to show the CommentText value in a text field. So I will create the
text field and it will contain the SQL that I have written. Can anyone help
me in this case?
It maybe simpler to use the SSRS function lookup (single paired 1 to 1) or lookupset (multiple 1 to many).microsoft lookup reference
You will have to create the query/dataset to return CommentText from LaborDtlComment table with the EmpID

Select max is returning a wrong value in MySQL

I have above table and I want to get the highest value from table bids where bid_id=60 using the following query
SELECT MAX(offer_amount) as maz FROM bids WHERE bid_id = 60
The problem is I'm getting the result as 80 in instead of the correct value which is 7000000
Anybody with an idea of how to solve this?
Store offer_amount in a numeric field (such as integer or decimal), not as text. Quick solution is to use the CAST() function in the query to cast the field's data type to a numeric one.

How to order by field if it contains number and text in mysql

I have data of address.I want to order address field to asc and desc order.
you can see in the table there are 2 fields id, address
If i order address field to desc.It should be have to come in below order
(1)5621 EMERSON CT
(2)5600 Emerson Court
(3)5393 Conestoga Dr.
But you can see in the image. It is not working properly. address field is varchar(255).
Can anyone please tell me what should i have to do not to solve this problem ?
Any help will be appreciated.
SELECT * FROM `address` ORDER BY cast(`address` AS SIGNED) ASC
In the above script Type caste the address column to int. So If your column has value like this means 1234 street. Mysql parse it as character so we forced mysql to parse it as int using datatype conversion function cast with data type signed int. so now mysql sees it as 1234 instead of 1234 street.
But if address column has value like this means junk 1234 now mysql interpret it to 0 by identify that value is started with non numeric character. so as a result if starts with number it works but not for other.
As this "address" is a string (varchar field), so it gets ordered lexically. So, you can probably order it by
SELECT `address` FROM 'table` ORDER BY convert(`address`, decimal) DESC;
This will solve the problem.

Mysql WHERE IN not working when i put swap the comma seperated value

I have this below weird problem with my mysql query. Correct me if i am wrong.
This below query( Which i have printed from Codeigniter ) giving me result with subject = 4.
WHERE `notes`.`subject` IN ('4,2') GROUP BY `notes`.`id` ORDER BY `created_date` DESC
But when i changed this
WHERE `notes`.`subject` IN ('2,4') GROUP BY `notes`.`id` ORDER BY `created_date` DESC
It is not returning any result. Why is that?
Lets say i have only one result in table and i am using codeigniter for this.
$this->db->where_in('notes.subject',$this->input->get('subject'));
in should have parameter string like
IN ('2','4'); // for varchar
IN (2,4) // for Integer values
the issue is here
$this->db->where_in('notes.subject',$this->input->get('subject'));
the input variable subject is a string for eg '2,4'
you can use $this->db->where_in('notes.subject',explode(",",$this->input->get('subject')));
which will pass an array to where_in
and as per the User guide
Second parameter to where_in() is an array
Try like this:
WHERE `notes`.`subject` IN ('4','2') ....
for Integers
WHERE `notes`.`subject` IN (4,2) ....

converting mysql query to hibernate hql

There is an Issue while i try to auto Increment alphanumeric Id (or number Series) for example
in Mysql "Sample" Table 'RefNo' column (of type Varchar)
AB7
AB10
AB9
AB8
above i have four entries now i want to retrieve max (or highest value).
for this i have tried query as = SELECT MAX(RefNo) FROM sample;
but this gives result as 'AB9' which is wrong and it is supposed to return 'AB10' as result.
To get this in Mysql i have modified the Query as
= SELECT MAX(CONVERT(SUBSTRING_INDEX(RefNo,'B',-1),UNSIGNED INTEGER)) from sample where RefNo like 'AB%'
this work's fine in mysql but in hibernate (hql) query is not supported.
I hope you understand the scenerio and Please help me to solve the issue.
You should be able to use substring and cast to get the numeric part of the string and cast it to a number. Something like that (not tested) :
select max(cast(substring(sample.refNo, 3) as INTEGER)) from Sample sample ...