Author |
Topic |
cornall
Posting Yak Master
148 Posts |
Posted - 2008-10-10 : 10:30:05
|
Hi,If I have a tableValue100200459.99234212121.1922323.89How do I SELECT only the values with a decimal place?Even better how do I UPDATE the recors to lose the decimal place without rounding the numbers up or down?Cheers Dave |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-10 : 10:34:16
|
What's the datatype of the column?you could doSELECT * FROM <yourtable> WHERE CONVERT(VARCHAR(255), <yourcolumn>) LIKE '%.%' Performance will.... suck but it would work.-------------Charlie |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-10 : 10:37:02
|
You can loose the decimal places by casting to intSELECT CAST(<yourColumn> AS INT) FROM <yourtable>-------------Charlie |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-10 : 10:38:31
|
for selecting -- quicker would be to use modulus (%)SELECT * FROM <yourTable> WHERE <youCol> % 1 <> 0 -------------Charlie |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-10 : 10:46:05
|
Transact Charlie, your methods would fail if there is data like 100.0MadhivananFailing to plan is Planning to fail |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-10 : 10:55:33
|
true -- yes I hadn't thought of that.In my defence there's nothing like that in the sample data.Presumably a cast to INT would still remove the . and likewise a LIKE comparison would still find it. Only the modulus wouldn't work?-------------Charlie |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-10 : 11:13:30
|
quote: Originally posted by Transact Charlie true -- yes I hadn't thought of that.In my defence there's nothing like that in the sample data.Presumably a cast to INT would still remove the . and likewise a LIKE comparison would still find it. Only the modulus wouldn't work?-------------Charlie
Your first method would workMadhivananFailing to plan is Planning to fail |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-10 : 11:21:32
|
madhivanan (as always) is right. And I'm not :(to drop the . point if the data is of a character type (which it looks like it is) you can't just CAST to INT directly.You can do this though.....SELECT CAST(CAST([value] AS DECIMAL(x,y)) AS INT) FROM <yourTable> Make sure that you give the decimal declaration enough scale (x) and precision (y) to deal with the widest value in your data.Thanks for the correction madhivanan.-------------Charlie |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-14 : 03:02:05
|
<<Thanks for the correction madhivanan.>>You are welcome MadhivananFailing to plan is Planning to fail |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-14 : 03:04:46
|
ROUND(Col1, 0, 1) vs ROUND(Col1, 0, 0) E 12°55'05.63"N 56°04'39.26" |
|
|
|