• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

tsql cmd to strip returns

I need the a tsql command that will strip of instances of a _trailing_ carragereturn/linefeed from a given field in a table.

thankx
--steve...
0
juststeve
Asked:
juststeve
  • 2
1 Solution
 
Scott PletcherSenior DBACommented:
Try one of these:

To UPDATE the column:
UPDATE tablename
SET column = LEFT(column,LEN(column) - 2)
WHERE RIGHT(column,2) = CHAR(13)+CHAR(10)

To SELECT the column:
SELECT CASE RIGHT(column,2) = CHAR(13)+CHAR(10) THEN LEFT(column,LEN(column) - 2) ELSE column END
FROM tablename
0
 
juststeveAuthor Commented:
thankx Scott....it appears to do what I want. The bit about the 'To SELECT the column:'... that's just so I can see what I'm going to update before I do so?
0
 
Scott PletcherSenior DBACommented:
Exactly; most people prefer to see what an update's going to do before they actually issue it.  Normally I would list the old and the new values but I didn't think you'd be able to see any difference in this case :-).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now