Share via

Refine the string

X M 20 Reputation points
2023-08-30T07:42:53.62+00:00

Hi,

Now I have a table with a list of strings that are messy in format with spaces before and after them, and I need to update the table to remove the spaces before and after the strings. How do I do this?

Thanks!

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Anonymous
2023-08-30T07:47:01.1666667+00:00

Hi @X M

You can try this.

create table test(col varchar(100));
insert into test values
('  asa '),
(' AD Lj'),
(' ad dag  '),
('  U PF GH   '),
(' V bag  h a ');

;with CTE as(
  select col,trim(col) as t from test)
update CTE set col = t;

Best regards,

Percy Tang

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.