Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-server-2005
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 at 21-Jan-13 11:44am
5 of course.
Marcus Kramer at 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)

Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
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