| Author |
Topic |
|
Gary Costigan
Yak Posting Veteran
95 Posts |
Posted - 2004-04-27 : 14:05:16
|
| I'm adding a table for one of our centers that has data with four digit numerics in two of the columns. Ie Column A = 4510, 4403, 4420. And Column B = 1000, 2000, 3000. In column B some of the values are 0000 which I need to have for a JOIN with another table. Each time I load the new table data from Excel or Access the 0000 turns into just one 0. For the life of me I can't figure out a way to format Column B so that it shows 0000.Thanks.GC |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2004-04-27 : 14:09:17
|
| make it a CHAR instead of an INT-ec |
 |
|
|
Gary Costigan
Yak Posting Veteran
95 Posts |
Posted - 2004-04-27 : 14:50:43
|
| EC,I originally had the format set to INT, but after digging into my SQL book yesterday had changed the column to CHAR without any luck. I tried it again just now and still nothing. I've made sure that the columns in Excel are formatted in the Custom setting as 0000. I dumped the old data and reloaded the table again and it still shows only one 0. If I open up the table to display all the rows and try to make an adjustment manually I get an error message. "The value you entered is not consistent with the data type or length of the column."I have the column set as CHAR and the length at 4.GC |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-04-27 : 14:55:11
|
| open up the table? EM?Use Query Analyzer to fix the data:UPDATE Table1SET Column1 = '0000'WHERE Column1 = '0'Tara |
 |
|
|
Gary Costigan
Yak Posting Veteran
95 Posts |
Posted - 2004-04-27 : 15:07:02
|
| Tara,Thanks, that did it! All "0" are now "0000". I did forget to mention that I have just one row where the value should be 0005, and instead is still showing 5. Can I use the same update placing a 5 in the there, or will it alter all the other 5's I have? Ie 2500 would change to 2000500.Thanks again.GC |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-04-27 : 16:03:27
|
| UPDATE Table1SET Column1 = '0005'WHERE Column1 = '5'It only finds exact matches.Tara |
 |
|
|
Gary Costigan
Yak Posting Veteran
95 Posts |
Posted - 2004-04-27 : 16:17:59
|
| Tara,That did it. Many thanks for all your help as always.GC |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-04-28 : 12:37:19
|
You might want to try...USE NorthwindGOCREATE TABLE myTable99(Col1 int)GOINSERT INTO myTable99(Col1)SELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3 UNION ALLSELECT 4 UNION ALLSELECT 5 UNION ALLSELECT 650GOSELECT * FROM myTable99ALTER TABLE myTable99 ALTER COLUMN Col1 CHAR(4)GOSELECT * FROM myTable99--Why don't these work?SELECT RIGHT(REPLICATE('0',4)+Col1,4) FROM myTable99SELECT REVERSE(SUBSTRING(REVERSE('0000'+Col1),1,4)) FROM myTable99GONever mind....what a scrub--This workedUPDATE myTable99 SET Col1 = RIGHT(RTRIM(REPLICATE('0',4)+Col1),4)SELECT * FROM myTable99GODROP TABLE myTable99GO Brett8-) |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-04-28 : 12:55:04
|
quote: Originally posted by X002548UPDATE myTable99 SET Col1 = RIGHT(RTRIM(REPLICATE('0',4)+Col1),4)
This will also do it:UPDATE mytable99 SET Col1 = RIGHT('0000' + RTRIM(Col1), 4)Slightly shorter Duane. |
 |
|
|
|