I am trying to replace a CRLF character in a table in SQL Server. The statement for one column works and goes like this:
select REPLACE(REPLACE(col_name,char(13),''), char(10), '') from table_name
Now I would like to repeat this for every column in my table. I have the following script which is not working:
Declare @sql varchar(max) = ''
select @sql = @sql + 'select [' + c.name + '] REPLACE(REPLACE(' + c.name + ', char(13),''), char(10), '') from [' + t.name + ']; '
from sys.columns c
inner join sys.tables t on c.object_id = t.object_id
where t.name = table_name
EXEC (@sql)
Unfortunately this doesn't work and I get the following error:
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near 'REPLACE'.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near 'REPLACE'.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near 'REPLACE'.
Msg 102, Level 15, State 1