| Author |
Topic |
|
hueby
Posting Yak Master
127 Posts |
Posted - 2005-11-17 : 11:33:10
|
| Hi all,I'm wondering if this is possible. I want need to add Leading Spaces to Column A, based on how long the value is in that column.If the text is 4 characters long I need to add 5 spaces in front, if the text is 5 characters long I need to add 4 spaces in front, and so on.There are thousands of rows, so I'm trying to see if this is something I run in QA quickly. Your thoughts? |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-11-17 : 11:44:09
|
| [code]USE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99(Col1 varchar(9))GOINSERT INTO myTable99(Col1)SELECT 'a' UNION ALLSELECT 'ab' UNION ALLSELECT 'abc' UNION ALLSELECT 'abcd' UNION ALLSELECT 'abcde' UNION ALLSELECT 'abcdefg' UNION ALLSELECT 'abcdefgh' UNION ALLSELECT 'abcdefghi'GOSELECT RIGHT(REPLICATE(' ',9) + Col1,9) FROM myTable99GOSET NOCOUNT OFFDROP TABLE myTable99GO[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2005-11-17 : 12:06:47
|
| Oh cool! That is exactly want I was wanting to accomplish. THANK YOU |
 |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2005-11-17 : 12:14:22
|
| ...now what is the best way to actually execute this on the table? |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-17 : 13:17:59
|
| At a guess:UPDATE USET Col1 = RIGHT(REPLICATE(' ',9) + Col1,9) FROM myTable99 AS UKristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-17 : 23:35:34
|
| Assuming that your original column is of varchar typeMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2005-11-18 : 15:34:02
|
Hi all, I ending up using:UPDATE VN_vendor_master_mcSET VN_vendor_master_mc.vendor_code = RIGHT(REPLICATE(' ',10) + vendor_code,10)where VN_vendor_master_mc.Company_code = 'HWP'Works great. THe only reason I had to do this, was because the software we use requires this. I was only doing a data dump and needed to format the columns so the software would take it. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
hueby
Posting Yak Master
127 Posts |
Posted - 2005-11-18 : 16:27:04
|
It is ForeFront by Dexter & Chaney. It is Job Costing / Accounting software for the construction industry.It has some quirks to it... |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2005-11-18 : 17:32:25
|
| In my experience, Account software is some of the worst designed database applications out there. Consistently bad. As if it was designed by accountants or something... |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-11-18 : 19:48:20
|
| "It has some quirks to it... ""As if it was designed by accountants or something..."Fantastic! Great way to end the week. Thanks guys!Kristen |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-11-18 : 20:02:53
|
| Designed by accountants who couldn't get or keep jobs as accountants... |
 |
|
|
|