Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a varchar to decimal

Status
Not open for further replies.

Dineedshelp

Technical User
Sep 27, 2002
44
0
0
GB
ARGH!!!!

I have tried and tried with this and probably the answer is staring me in the face!!!!

I have a field call hrs_worked,varchar(5) and basically holds the number of hours a person has worked. I need to convert this figure to a decimal figure.

I have tried a combination of cast and convert functions and nothing appears to work!!!

Please help!!!!!!
 
This worked for me, I think it is doing what you want:

Code:
declare @vc varchar(5)
declare @d decimal(5,2)

select @vc = '10.11'

select @d = convert(decimal(5,2), @vc)

select @vc,@d

Output
10.11 10.11
 
In fact you don't even need the convert!

Code:
declare @vc varchar(5)
declare @d decimal(5,2)

select @vc = '10.11'

select @d = @vc

select @vc,@d


Output
10.11 10.11
 
SELECT CONVERT(decimal(10,5), columnName) from tableName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top