phpMyAdmin - error in your SQL syntax

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'float) *         (case right(disk_space_size, 2) when 'GB' then

mysql coding

select disk_space_size,
       (cast(left(disk_space_size, locate(' ', b)) as float) *
        (case right(disk_space_size, 2) when 'GB' then 1.0
                            when 'TB' then 1024.0
                            when 'MB' then 1.0/1024
                            else 1.0
         end)) as inGB
from nov;
Scott Yong Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
for the left function, shouldn't you to provide the 2nd parameter for the length?

 (cast(left(disk_space_size, locate(' ', b)) as float) *
0
Scott Yong Author Commented:
Disk Space Size
256 GB
200 GB
200 GB
8.64 TB

I want to convert Tb  to converted to GB. yes I don't want the TB or GB or MB to be displayed in disk space size column .just numbers.
0
Vaibhav GoelMSBI , SQL ConsultantCommented:
Hello Scott Yong

Please make an attempt for changed code below.

select disk_space_size,
       
           cast(left(disk_space_size, locate(' ', b)) as float)
           *
         CASE WHEN RIGHT(disk_space_size, 2) = 'GB' then 1.0
             when RIGHT(disk_space_size, 2) = 'TB' then 1024.0
             when RIGHT(disk_space_size, 2) = 'MB' then 1.0/1024
             else 1.0
         end
             
             inGB
from nov;

Vaibhav
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Scott Yong Author Commented:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'float)
           *
         CASE WHEN RIGHT(disk_space_size, 2) = 'GB' then ' at line 3
0
Dave BaldwinFixer of ProblemsCommented:
Looks to me like you need a comma after the *.
0
Vaibhav GoelMSBI , SQL ConsultantCommented:
Hello Scott Yong

Please make an attempt for changed code below.

select disk_space_size,
       
           CAST(left(disk_space_size, locate(' ', b)) AS DECIMAL(10,2))
           *
         CASE WHEN RIGHT(disk_space_size, 2) = 'GB' then 1.0
             when RIGHT(disk_space_size, 2) = 'TB' then 1024.0
             when RIGHT(disk_space_size, 2) = 'MB' then 1.0/1024
             else 1.0
         end
             
             inGB
from nov;

Vaibhav
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongCommented:
Dave is correct,

you missing a comma after *

 *
,         CASE
1
Scott Yong Author Commented:
thank for help me .. success already
0
Vaibhav GoelMSBI , SQL ConsultantCommented:
Hello All

The Author was multiplying.

@Scott Yong - Pleased to know that it helped.  Thank You

Vaibhav
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.