How To Replace Newline Character From The SQL Server Field

Description

In this post, we will learn about how to replace newline characters from SQL fields. In this post, we have to use replace function for replace string and also use char function to remove newline characters and replace them. Here I will give you the syntax of replace function, how to use char function, and the meaning of 10 in char function.
 
Syntax
  1. REPLACE(string, string_to_replace, replacement_string)  
Description of parameter value,
  • string - Source string
  • string_to_replace - String to search for in string1
  • replacement_string - Replacement string will be replaced string_to_replace with replacement_string in string1
What Char(10) in SQL. Execute the below selected query for checking what char(10) contains. Char(10) displays blank result in SQL query result which means it's \r or \n
  1. SELECT CHAR(10) 
Below query replaces char(10) to html <br /> tag,
  1. REPLACE(EventNote, CHAR(10),'<br />'
See the 4th result in the screenshot for replacing string display with HTML <br /> tag.