I have a table that looks like this:
id datatype name value
0 nvarchar(255) myName 'Paul'
1 int age '30'
2 float(53) Custom1 0.5
3 float(53) Custom2 1.3
4 float(53) Custom3 2.7
I am wondering if it is possible to do something like the following where I cast the order by as a float – I know this is incorrect syntax but wondering if this can be done.
SELECT datatype, name, value FROM myTable
ORDER BY (float)name
Thanks in advance.
To convert datatypes in SQL you can use CAST or CONVERT:
But if your name field contains a value that cannot be converted to a valid float, you’ll get an error.
e.g.
will give you: