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.
| Author |
Topic |
|
MaryamFarmani
Starting Member
2 Posts |
Posted - 2007-06-06 : 12:42:42
|
| select numberemployees, convert(int, substring (numberemployees, 1, (charindex ('.',numberemployees)-1)))from adagency numberemployees is a (varchar, 4)With this code I get number of employees in an integer format and that’s what I want. But the problem is with those numbers without '.'I mean it works fine with a number like 26.5, which returns 26 ...But I get error on converting a number like 26Any idea about solving this issue?Appreciated in advance!Maryam |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-06 : 12:45:09
|
| [code]select convert(int, convert(float, numberemployees))From adagency [/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2007-06-06 : 12:47:53
|
| You can also use the CAST function:SELECT CAST(CAST(NumberEmployees AS FLOAT) AS INT) as NumberEmployeesFROM adagencySQL Server Helperhttp://www.sql-server-helper.com |
 |
|
|
MaryamFarmani
Starting Member
2 Posts |
Posted - 2007-06-06 : 12:56:36
|
| Yes, it works...Thanks and God bless you! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-07 : 10:47:36
|
| Why did you use varchar datatype to store numbers?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|