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 |
|
shifis
Posting Yak Master
157 Posts |
Posted - 2010-02-22 : 23:10:45
|
| HiI need to make a rtrim(ltrim(column)) to all columns of a table.What is the best way? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
shifis
Posting Yak Master
157 Posts |
Posted - 2010-02-22 : 23:32:36
|
| You are right, the data come from an instruction BULK INSERT, the SP put the data that come from a txt into a table where all the columns are 255 long. Then it started to made validations, but each time that this happen they uses rtrim(ltrim(column)). |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-23 : 02:04:06
|
| IF you use varchar, leading spaces are truncated automatically. If datatype is char , you should use rtrimTry thisdeclare @sql varchar(1000)set @sql=''select @sql=@sql+'ltrim(rtrim('+column_name+')),' from information_schema.columnswhere table_name='table_name'set @sql='select '+substring(@sql,1,len(@sql)-1)+' from table_name'exec(@sql)MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-23 : 03:02:15
|
" IF you use varchar, leading spaces are truncated automatically"Madhi: That doesn't read right, as I read it anyway!DECLARE @MyTable TABLE( MyCol varchar(100))INSERT INTO @MyTableSELECT ' foo bar 'SELECT ']' + MyCol + '[' FROM @MyTable |
 |
|
|
|
|
|