Change SQL result on the fly?
I have a SQL query: SELECT DATEDIFF(deadline,CURDATE()) FROM tasks WHERE 1
Result: 3
How can I return the result as: 3 Days
instead of3
I know I can manually add a line from my C # code something like this:
string result = getSqlresult();
string result += " Days";
But I want to get the result directly as 3 Days
from the MySQL database.
Reason:
I am binding information directly to the datagridview and therefore, in order to change the result, I need to iterate over all the rows and update them. To improve performance, I need to get the result directly from the database like 3 Days
instead3
Anyhelp will be highly appreciated
source to share
you can link the string Days
to the result DATEDIFF
with CONCAT
.
SELECT CONCAT(DATEDIFF(deadline,CURDATE()), ' Days')
FROM tasks
WHERE 1
if you are using older versions MySQL
, convert it to string so you don't get the result bolb
.
SELECT CONCAT(CAST(DATEDIFF(deadline,CURDATE()) AS CHAR(5)), ' Days')
FROM tasks
WHERE 1
UPDATE 1
SELECT CASE
WHEN DATEDIFF(deadline,CURDATE()) >= 0
THEN CONCAT(DATEDIFF(deadline,CURDATE()), ' Days')
ELSE CONCAT('Expired since ', DATEDIFF(deadline,CURDATE()) * -1, ' Days')
END
FROM tasks
source to share