views:

133

answers:

2

I have a table in a SQL server 2000 database with a nvarchar(30) field "details". There are some 10,000 records in that with a trailing space. I need a query to trim the particular field content in all rows. How can I achieve this?

Thanks.

+1  A: 

If you wish to do this in a select statement only, use

SELECT RTRIM(Val)
FROM Table

If you wish to change the values in the table, use update

UPDATE Table
SET Val = RTRIM(Val)

For padding puposes you can use replicate

SELECT REPLICATE('*', 10) + 'TADA'
astander
+1  A: 
UPDATE table SET details = RTRIM(details)

For padding, you could do, for instance:

UPDATE table SET details = details + '    '

or

UPDATE table SET details = '    ' + details
Jonas Lincoln
Thanks. How to pad the entries purposely with some leading or trailing characters?
bdhar
Use replicate for padding...
astander