0
select
    replace(Street, char(10), '')
from streettable

Have explored the syntax of replace function ...but how does this piece of code work?

2
  • What exactly are you trying to do? REPLACE is usually used to change the content of a value rather than its type. Commented Jun 15, 2015 at 12:04
  • 1
    This is not changing the type, in this case CHAR(10) is not defining a type of CHAR with a length of 10, is it the scalar function CHAR() returning the ASCII character 10 (line feed). Commented Jun 15, 2015 at 12:11

1 Answer 1

3

The sample code doesn't change datatype. char(10) is line feed and the code just replaces line feeds with empty symbol in street column(not in table, but on the fly to present. Data in table stays untouched).

If you want to change datatype then you should alter the column. Something like:

alter table streettable alter column Street varchar(777) null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.