Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help using SQL Convert

Author  Topic 

drew22299
Starting Member

26 Posts

Posted - 2009-01-23 : 05:35:23
Hi,

I'm not sure where to put the convert clause in my SQL code, does it go after the Select statement and before the from clause?

Here is my SQL code:

Select statement

CONVERT(integer,(CONVERT(decimal,Scores.Score) / CONVERT(decimal,Scores.MaximumScore) * 100),0) AS ScorePercentage

From


But I get the following error: Incorrect syntax near the keyword 'CONVERT'

Can anyone see why?

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-23 : 05:41:02
Try this

Select CONVERT(integer,(CONVERT(decimal,34) / CONVERT(decimal,200) * 100),0) AS ScorePercentage
Go to Top of Page

drew22299
Starting Member

26 Posts

Posted - 2009-01-23 : 05:45:51
Should convert clause be part of the select statement? I still get the same error.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-23 : 05:45:54
quote:
Originally posted by drew22299

Hi,

I'm not sure where to put the convert clause in my SQL code, does it go after the Select statement and before the from clause?

Here is my SQL code:

Select statement

CONVERT(integer,(CONVERT(decimal,Scores.Score) / CONVERT(decimal,Scores.MaximumScore) * 100),0) AS ScorePercentage

From


But I get the following error: Incorrect syntax near the keyword 'CONVERT'

Can anyone see why?





Select statement

CONVERT(integer,(CONVERT(decimal,Scores.Score) / CONVERT(decimal,Scores.MaximumScore) * 100),0) AS ScorePercentage

From

Go to Top of Page

drew22299
Starting Member

26 Posts

Posted - 2009-01-23 : 05:51:32
Thanks, I just realised I missed out a comma, but now I get an error saying the columns Scores.Score and Scores.MaximumScore cannot be bound

Why is this? The table joins are correct and if I comment out the line with the convert clause I can get data from both of the fields?
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-23 : 06:05:52
can U post Ur Query and check ur tablename or alias names for table
Go to Top of Page

drew22299
Starting Member

26 Posts

Posted - 2009-01-23 : 06:09:28
I managed to fix it, one of the fields didn't have the correct spelling.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-23 : 06:12:51
quote:
Originally posted by drew22299

I managed to fix it, one of the field names were spelt incorrectly.


ok
Go to Top of Page
   

- Advertisement -