Operand data type nvarchar is invalid for divide operator.
The error message you got is clear enough. You can apply divide calculation only on numeric data, not on string value. It seems that total_deaths
or total_cases
are Nvarchar
type. You may have to convert the strings to numeric first.
Try this:
select location, date, total_cases, total_deaths, (CONVERT(DECIMAL(18,2), total_deaths) / CONVERT(DECIMAL(18,2), total_cases) )*100 as DeathPercent
from ProjectPortfolio..CovidDeaths
order by 1,2
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.