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 |
|
veparala
Starting Member
30 Posts |
Posted - 2007-02-13 : 16:52:10
|
| Hi I would like to trim numeric values. i.e i have numeric data with datatype(10,0). But i would like to take only 5 numbers from that numeric value.ExampleIf the value in the numeric field is 8294724724. I would like to get only first 5 numbers. i.e 829472.Anybody help me on this?. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-13 : 18:11:47
|
[code]declare @n numeric(10,0)select @n = 8294724724select left(@n, 5) -- returns a varchar typeselect convert(numeric(10,0), left(@n, 5)) -- convert back to numeric[/code] KH |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-02-13 : 22:56:32
|
also you can just use integer arithmetic:select cast(8294724724/10000 as int) www.elsasoft.org |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-13 : 23:06:34
|
quote: Originally posted by jezemine also you can just use integer arithmetic:select cast(8294724724/10000 as int) www.elsasoft.org
Why i didn't think of that  KH |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-02-14 : 10:15:42
|
you were just throwing a bone to a poor guy with only 400 posts...  www.elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-14 : 10:42:10
|
Maybe not all numbers have ten digits?declare @t table (a numeric(10,0))insert @tselect 8294724724 union allselect 234242 union allselect 35903 union allselect 34238490select a, floor(a / power(10, floor(log(a) / log(10)) - 4))from @t Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|