SELECT YEAR, Strata, Strata_Name, FORMAT([%]/10000, 'P') [%] FROM [dbo].[Depression_in_California] WHERE Strata_Name = 'Male' ORDER BY [%] desc;
the column is float not null
Advertisement
Answer
You have a numeric column called [%]
and you are naming your calculated column [%]
too. The type of your calculated value if nvarchar.
As pointed out by @Tarik, it looks like SQL Server is ordering the result by the calculated column (alias). I think it would be much more clear to use a different alias name, for example:
SELECT YEAR, Strata, Strata_Name, FORMAT([%]/10000, 'P') PercentageOfDepression /* <-- calculated nvarchar */ FROM [dbo].[Depression_in_California] WHERE Strata_Name = 'Male' ORDER BY [%] desc; /* <-- numeric [%] */