Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 convert to varchar

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2010-04-06 : 04:56:53
how i convert to varchar?

i have this number: 123.44

i want 123 (in varchar)

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-04-06 : 04:59:13
CONVERT(VARCHAR, FLOOR(123.44))

Vaibhav T
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-06 : 04:59:54
Try
convert(varchar(10),convert(int,your_col))


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-04-06 : 05:00:37
Select cast ( cast(123.44 as int) as varchar(5))

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-06 : 05:13:05
quote:
Originally posted by inbs

how i convert to varchar?

i have this number: 123.44

i want 123 (in varchar)


Why do you want it as varchar?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-06 : 05:21:48
quote:
Originally posted by vaibhavktiwari83

CONVERT(VARCHAR, FLOOR(123.44))

Vaibhav T


Always specify a length while converting to varchar.
see reason below

http://visakhm.blogspot.com/2010/02/importance-of-specifying-length-in.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-06 : 05:23:51
other points

http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -