Home > Mobile >  Incorrect syntax near 'cast', expected 'AS'- SQL Project
Incorrect syntax near 'cast', expected 'AS'- SQL Project

Time:01-07

I am watching this video from Alex Freburg: https://www.youtube.com/watch?v=qfyynHBFOsM.

At 33.43 mins he has done some code on the server, the exact I have copied but I get this error message:

Incorrect syntax near 'CAST', expected 'AS'

The code I have tried to run is this:

Select location, MAX(CAST(total_deaths) AS int)) AS TotalDeathCount
From [Portfolio Project]..CovidDeaths$
group by location
order by TotalDeathCount desc

Any help would be appreciated.

I tried a variety of things but not sure why it is not working like the video above.

CodePudding user response:

Select location, MAX(CAST (total_deaths AS integer )) AS TotalDeathCount From [Portfolio Project]..CovidDeaths$ group by location order by TotalDeathCount desc

Or

Select location, MAX(total_deaths:: integer ) AS TotalDeathCount From [Portfolio Project]..CovidDeaths$ group by location order by TotalDeathCount desc

CodePudding user response:

There's an extra closing right paren ())

MAX(CAST(total_deaths) AS int)) 

should be

MAX(CAST(total_deaths AS int)) 
  • Related