我試圖在SQL Server中的表中替換CRLF字符。一列的聲明的工作原理是這樣的:遍歷列的SQL循環並執行REPLACE語句
select REPLACE(REPLACE(col_name,char(13),''), char(10), '') from table_name
現在我想對我的表中的每一列重複一遍。我有以下腳本,不工作:
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)
不幸的是,這並不工作,我得到了以下錯誤:
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
剛注意到,你使用select,但是如果你想擺脫那個,你需要更新。添加到我的答案。 – gofr1