Cliff Crerar Cliff Crerar - 1 month ago 9
SQL Question

InterBase - Casting calculated column as varying character

I am attempting to write a query that uses a calculated value, I then want to cast this calculated value as a string so that I can add a '%' to the end.

However I am not succeeding with the query below:

select
a.Subjects, a.RequiredTime, b.HRS,
CAST(((b.HRS / a.RequiredTime)*100) as VARCHAR) as PercentageComplete
from
Subjects a
inner join
V_SUMMARYHOURSSUBJECT b on a.Subjects = b.Subject


This is the error that the query generates:


Error at line 1 Dynamic SQL Error SQL error code = -104 Token unknown
- line 2, char 46 ) SQL

Answer

When you want to convert from integer/numeric/double to a string using InterBase SQL; a string length must be specified as part of the CAST function for example

select a.Subjects, a.RequiredTime, b.HRS,
CAST(((b.HRS / a.RequiredTime)*100) as VARCHAR(10)) as PercentageComplete
from Subjects a inner join V_SUMMARYHOURSSUBJECT b
on a.Subjects = b.Subject