i am converting a varchar type to int..
sum(cast(Replace([ExtraWokedHrs],'Mins','')as int)) as [ExtraWokedHrs]
but i am getting an error...
Msg 245, Level 16, State 1, Procedure PerfomanceReport, Line 544
Conversion failed when converting the varchar value '0 Mins' to data type int.
PLS help
Loading

Manikavelu VelayuthamRank #413 · 6K reputationPosted Nov 9, 2010, 10:22 PM EST
How it will convert '0 Mins' to a Integer. 'Mins' is a word.
Only the numerical strings can be converte into Integer variable.
Eg:-
'123' --> can be converted to 123
'12' --> can be converted to 12
'1' --> can be converted to 1
Natarajamani Venugopal20 reputationPosted Nov 9, 2010, 10:58 PM EST
Manikavelu VelayuthamRank #413 · 6K reputationPosted Nov 9, 2010, 11:08 PM EST
create table test(ExtraWokedHrs vARCHAR(50))
insert into test values ('21Mins')
insert into test values ('22Mins')
insert into test values ('23Mins')
insert into test values ('24Mins')
select sum(cast(Replace(ExtraWokedHrs,'Mins','')as int)) as ExtraWokedHrs from test
ExtraWokedHrs
90
Natarajamani Venugopal20 reputationPosted Nov 9, 2010, 11:47 PM EST
Suthish NairRank #92 · 22.8K reputationPosted Nov 9, 2010, 11:49 PM EST
Manikavelu VelayuthamRank #413 · 6K reputationPosted Nov 9, 2010, 11:55 PM EST