February 23, 2015 at 2:01 pm
I dont know why this seems to be so difficult. I have searched all over the web and these forums, yet no one seems to have dealt with my current situation.
I have a varchar column with values: 100%, 50%, 30%, etc. I am trying to convert these to float: 1.00, 0.50, 0.30, etc. When I try to cast or convert I get an error because of the '%'. When I try to replace to '%' with ' ' , I get an error. This seems so silly, yet I can't figure it out.
February 23, 2015 at 2:20 pm
I can't reproduce your problem. Or maybe you're doing something different.
CREATE TABLE Test(
string_pct varchar(10))
INSERT INTO Test
VALUES
('100%'),
('50%'),
('30%'),
('10%')
SELECT string_pct,
CAST( REPLACE(string_pct, '%', '') AS float) / 100
FROM Test
GO
DROP TABLE Test
February 23, 2015 at 2:28 pm
wonderful, that fixed my problem. Im not sure why when I tried the following it failed. Again, thans a bunch
replace(string_pct, '%', ' ')
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply