Error Code: 1525. Incorrect DATE value using STR_TO_DATE [closed] - mysql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
why do I receive this error:
Error Code: 1525. Incorrect DATE value: '01-01-2017'
When using this query:
CREATE VIEW 2017Employees AS
SELECT EmployeeID
FROM contract
WHERE `Start` <= STR_TO_DATE('01-01-2017','%d-%m-%y')
AND DueFinish>= STR_TO_DATE('31-12-2017','%d-%m-%y');
I thought that the function STR_TO_DATE converted strings to dates.

You have to use %Y instead of %y because you are using year with four digits:
CREATE VIEW 2017Employees AS
SELECT EmployeeID
FROM contract
WHERE `Start` <= STR_TO_DATE('01-01-2017','%d-%m-%Y')
AND DueFinish>= STR_TO_DATE('31-12-2017','%d-%m-%Y');
You can find all available format specifier with a explanation on the documentation of DATE_FORMAT:
%Y - Year, numeric, four digits
%y - Year, numeric (two digits)

Related

How can I add brackets to each word of a string which contains multiple words in SQL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
The community reviewed whether to reopen this question 5 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I add brackets to each word of a string which contains multiple words in SQL? For example, I have:
string example = 'word1,word2,word3,word4,word5'
How can I convert it to something like this:
string example = '[word1],[word2],[word3],[word4],[word5]'
We can use a combination of REPLACE() and string concatenation:
SELECT val, CONCAT('[', REPLACE(val, ',', '],[') , ']') AS output
FROM yourTable;
On MySQL 8+, we can use a regex replacement:
SELECT val, REGEXP_REPLACE(val, '([^,]+)', '[$1]') AS output
FROM yourTable;

Converting tomcat logs to CSV using sed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I have some application log data on a Linux server, which looks like this:
Jan 11 14:24:42 AttackSimulator.abcd [1587566256,49294,"ryan.wright#abcd.com",3237159933,1,0,0,3,"2314","https",443,2899903330,"https://googleads.g.doubleclick.net/pagead/ads",0,"","","","","1 - Default Policy","","googleads.g.doubleclick.net","GET",4,0,5]
Jan 11 14:24:42 AttackSimulator.abcd [1587566256,49294,"melisa.zeunert#abcd.com",3237159933,1,0,0,3,"2339,37788","http",80,387803624,"http://ping.citrix.com",0,"","","","","3 - Extended Policy High","","ping.citrix.com","HEAD",3,0,4]
I want to output this in a CSV file. Everything between the [ ] should be part of the CSV with column names such as DateandTime, AccountID, UserID, ClientIP etc. Something that looks like this:
DateandTime, AccountID, UserID, ClientIP
1587566256,49294,"ryan.wright#abcd.com",3237159933
1587566256,49294,"melisa.zeunert#abcd.com",3237159933
(This is just an example with only 4 columns. Actual output would have 25)
Any input would be helpful
Using sed
$ sed 's/.*\[\(.*\)]/\1/;1iDateandTime, AccountID, UserID, ClientIP ' file
DateandTime, AccountID, UserID, ClientIP
1587566256,49294,"ryan.wright#scnx.com",3237159933,1,0,0,3,"2314","https",443,2899903330,"https://googleads.g.doubleclick.net/pagead/ads",0,"","","","","1 - Default Policy","","googleads.g.doubleclick.net","GET",4,0,5
1587566256,49294,"melisa.zeunert#scnx.com",3237159933,1,0,0,3,"2339,37788","http",80,387803624,"http://ping.citrix.com",0,"","","","","3 - Extended Policy High","","ping.citrix.com","HEAD",3,0,4
.*\[ - Exclude everything up to the last [ square bracket.
\(.*\)] - Include everything within the parenthesis up to the last ] square bracket
\1 - Return with back reference the contents stored inside the parenthesis
1i - Insert on line 1

Mysql - How to find max Value with decimal [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
In the mysql table (books_title) have 144 records.
The column book_progressive contain this values for rows:
01.01
02.01
03.01
...
99.01
100.01
101.01
102.01
...
144.01
When check the max value with this query:
select max(book_progressive) from books_title
return 99.01, but the max value is 144.01.
How to resolve this?
Thanks
It looks like your book_progressive is declared as CHAR/VARCHAR and not DECIMAL.
Change your column type , or CAST the result :
select max(CAST(book_progressive AS DECIMAL(10,2)) from books_title
I find a Solution with LPAD because the max value is found only if the number of characters is equal
select max(lpad(book_progressive,6,0)) from books_title
Thans

How can I add values into MySQL if the value is either string or float? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am parsing an excel file and adding the values im getting into a database. But one of the columns I am parsing can be either a float or a string. Like such: 0,45 or Contact Support. What is the best way for me to add this as it is, to my database? Or more how should I format my database column for this?
use varchar datatype(in MySQL) for the column you want to parse and you can save both the integer and character values.
I recommend you create a float type column and a varchar column. Write your parser so that valid float values are filled to the float column and the rest to the varchar one. This will allow you to both sort your database by the value of the float type column and run queries on fields that are missing that value: SELECT * FROM mytable WHERE myfloat IS NULL
first am with Kaivosukeltaja answer.
but if you can't do that, make a varchar column to save the strings or doubles.
BTW when you get data from a database all the data comes in string format then you can cast it to any type you want.
if you are using PHP:
$x = $row['string_double_column'];
if(is_numeric($x))
return doubleval($x);
else
return $x;

Append $ character to a MySQL DB field so that length is increased by 40 % [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to append any character, say $, to the name of the student field in database such that its length is increased by 40 %, and save the result in the database.
E.g.:
Name: VijayKumar
After update:
Name: VijayKumar$$$$
You would use concat() and repeat():
select concat(name, repeat('$', ceil(length(name) * 0.4))