I have a demand to eliminate trailing spaces in a table column. The column is of varchar datatype, so I imagine that doing an export to a flatfile and re-importing will automatically get rid of trailing blank after the data ????
Can anyone think of an alternative approach ?Ever thought on using standard functions? {L/R}TRIM() removes leading and trailing spaces. So, all you have to do is:
UPDATE <YourTable>
SET <YourColumn> = rtrim(<YourColumn>)|||Oeps,
My guess was that it was varchar datatype . I was wrong , it is of type 'text' (I am an DB2 / ORACLE guy, so I expected other field type)
The RTRIM function does not seem to work with 'text' datatype.....|||If you did not expect the datatype TEXT, are you sure that it has to be TEXT? Consider changing your structure!|||The SQL database is part of an application we bought. I am afraid that changing the structure will invalidate support on the whole package. The column contains names of picture files. Is there a specific reason to go for a text field in that case?|||You mean the path to the picture files? I suspect that the application designer expected paths longer than 255 characters, which is in some DBMS the limit for a VARCHAR datatype. However, SQL Server allows 4000 characters, which should be sufficient. So, you may refine your update statement as follows:
UPDATE <YourTable>
SET <YourColumn> = rtrim( cast(<YourColumn> AS NVarChar(4000)) )|||Hey doctor,
I did what suggested in your last post, but used the convert() function instead. Nice this T-SQL stuff, feels like eating a different kind of food..|||See Simple Question About Data Type (http://dbforums.com/t897663.html) for a discussion about CAST() and CONVERT(). Disregard the last few messages as they are irrelevant for the thread.
Wednesday, March 21, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment