September 27, 2005 at 11:49 am
Hi,
I have a column which is stored in database as varchar.The vaue it contains is like '1/8'(ratio).
I need to use this in calculations,I am not able to use cast or convert as it taking '/' and not evaluating the ratio.is there any way I can do this?
Thanks,
Ssm
SSM
September 27, 2005 at 11:50 am
Can you post more information >
- Table definition
- Sample data
- Required results
September 27, 2005 at 12:20 pm
The data type of column is varchar(512),
Sample values are
1/7
1/8
1/6
1/9
I need to divide by these ratios.
Thanks,
ssm
SSM
September 27, 2005 at 12:52 pm
Declare @demo table (Ratio varchar(7) not null primary key clustered)
Insert into @demo (Ratio) values ('4/7')
Insert into @demo (Ratio) values ('1/6')
Insert into @demo (Ratio) values ('1/7')
Insert into @demo (Ratio) values ('1/8')
Insert into @demo (Ratio) values ('1/9')
Insert into @demo (Ratio) values ('11/92')
Insert into @demo (Ratio) values ('/92')
SELECT
dtRatios.Ratio
, dtRatios.Numerator
, dtRatios.Denominateur
, dtRatios.Numerator / dtRatios.Denominateur AS fFloat
FROM
(
SELECT
Ratio
, CONVERT(INT, LEFT(Ratio, Charindex ('/', Ratio, 1) - 1)) AS Numerator
, CONVERT(DECIMAL(18,1), RIGHT(Ratio, LEN(Ratio) - (Charindex ('/', Ratio, 1)))) as Denominateur
FROM @demo
WHERE Charindex ('/', Ratio, 1) > 1
) dtRatios
September 28, 2005 at 1:01 pm
Thanks,
ssm
SSM
September 28, 2005 at 1:04 pm
HTH.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply