我试图在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