Click here to Skip to main content
12,886,892 members (36,621 online)
Rate this:
Please Sign up or sign in to vote.
how to convert varchar to int if i have varchar value like 125.22 . I want to convert this as int like 125.

Help me
Posted 21-Jan-13 3:35am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The simplest answer I can give you is: CAST and CONVERT - TSQL[^]

A second one with example: Source[^]
create table #work
  something decimal(8,3) not null 
insert #work values ( 0 )
insert #work values ( 12345.6789 )
insert #work values ( 3.1415926 )
insert #work values ( 45 )
insert #work values ( 9876.123456 )
insert #work values ( -12.5678 )
select convert(varchar,convert(decimal(8,2),something))
from #work
if you want it right-aligned, something like this should do you:
select str(something,8,2) from #work

Abhinav S 21-Jan-13 11:44am
5 of course.
Marcus Kramer 21-Jan-13 13:38pm
Thanks, Abhinav

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100