| Author |
Topic |
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 12:12:19
|
| I have spent all morning on Google and various forums and have not been able to get this to work. I am trying to get column IL converted from varchar(10) to numeric(7,2). I have tried the following:select * into #tmp from MyTabletruncate table MyTablealter table MyTablealter column IL numeric(7,2) insert into MyTableselect cast(IL as numeric(7,2))drop table #tmp -----UPDATE MyTableSET IL = CAST (IL AS numeric(7,2)) ------ALTER TABLE MyTableALTER COLUMN IL numeric(7,2)-------None of these things worked. Any ideas? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-12-16 : 12:21:03
|
| How does it not work? ARe you getting a conversion error?ALTER TABLE MyTableALTER COLUMN IL numeric(7,2)Should work just fine. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 13:59:48
|
| Lamprey: I get the following error when I try thatArithmetic overflow error converting varchar to data type numeric.X002548 (Brett):That returns nothing. Just every column header. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-12-16 : 14:02:16
|
| Well there you go. You could check to see if any of the values are longer than 7 characters for a start. After that, you could try to narrow things down in other ways. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:10:37
|
| so basically if I change my numeric from (7,2) to something like (12,2) it should work? Assuming the longest value is 12? |
 |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:13:27
|
| Brett:-0.01-0.03-0.76-10-100-100-100-100-100-100-100-100-100-100-100-100-100-100-100-1009999.659999.389997.459997.279995.679995.659995.099994.719994.689993.699993.479993.319991.639991.259991.1899919990.99990.389990.159990.08 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:23:56
|
| --What does ----SELECT MAX([IL]) FROM Table tell you?Just 9999.65 again |
 |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:27:44
|
| The querySELECT MAX(len([IL])) FROM MyTablebrings back 12. Should I try numeric(12,2)? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:39:17
|
quote: Originally posted by X002548 DECLARE @v CHAR(10); SET @v = '9999.65'SELECT CONVERT(decimal(7,2),@v)SELECT CONVERT(decimal(15,2),@v)
I don't understand the context of what's going on here. How does this reference IL or MyTable? Do I need to include something else? what does @v mean?Thanks,Justin |
 |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:43:24
|
quote: Originally posted by X002548CREATE TABLE #t1(IL decimal(7,2))CREATE TABLE #t2(IL decimal(15,2))INSERT INTO #t1 (IL)SELECT IF FROM myTableINSERT INTO #t2 (IL)SELECT IF FROM myTableDoes either work?
lol, they both err out but with different error messages!The first one gives me the arithmetic error"Arithmetic overflow error converting varchar to data type numeric."The second one gives me the following error:"Error converting data type varchar to numeric."Thanks,Justin |
 |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:44:13
|
| Oh, and I assumed by SELECT IF FROM myTable you actually meant SELECT IL FROM myTable |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 14:53:31
|
| No running with IL was where I came up with those two errors. |
 |
|
|
JustinM
Starting Member
17 Posts |
Posted - 2011-12-16 : 16:57:24
|
| I ended up reimporting the file and changing the format at import. Looks like it worked okay. Not sure what was going on before that, but the fact that you guys were suggesting things similar to what I was doing makes me feel better about the whole process. Thanks for all your help! |
 |
|
|
|