Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL2005
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:35


1 solution

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
  Permalink  
Comments
Abhinav S - 21 Jan '13 - 11:44
5 of course.
Marcus Kramer - 21 Jan '13 - 13:38
Thanks, Abhinav

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 253
2 OriginalGriff 200
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid