I have a table sales having attributes as salesId,salesDate,..etc. The salesId column is a varchar.I need to concat the year value of the salesDate to the salesId based on a condition of the month of the salesDate. I need to do this for a range of around 100 salesID.
Eg: old salesId = 7 and corresponding salesDate = '2018-05-07' then new required
salesId = '7/2018-2019'
So i tried the following :
update sales
set salesId = case
when month(salesDate)>=4 then concat(salesId,concat("/",year(salesDate),"-",year(salesDate)+1))
else
concat(salesId,concat("/",year(salesDate)-1,"-",year(salesDate)))
end
where cast(salesId as unsigned) between "7" and "10";
However, i get the following error:
Error Code: 1292. Truncated incorrect INTEGER value: '1/17-18'
I even tried without using any Cast() as
update sales
set salesId = case
when month(salesDate)>=4 then concat(salesId,concat("/",year(salesDate),"-",year(salesDate)+1))
else
concat(salesId,concat("/",year(salesDate)-1,"-",year(salesDate)))
end
where salesId between "7" and "10";
but in this case the query runs fine but i get:
0 row(s) affected Rows matched: 0 Changed: 0 Warnings: 0
I can't figure out the error or how to proceed.Could someone please provide some guidance in this ? Thanks. Sample data
salesId salesDate
7 2017-05-15
8 2017-06-16
9 2017-07-18
10 2017-08-20
...
Required Result
salesId salesDate
7/2017-2018 2017-05-15
8/2017-2018 2017-06-16
9/2017-2018 2017-07-18
10/2016-2017 2017-02-20