怎么把空格替换成''
如何把空格替换成','
--> 建立数据表#temp --数据表#temp里有'notext'字段记录
--------------生成数据--------------------------
--> 测试数据
--楼主代码
notext字段的结果是
请问如何修改代码,如何把字段notext里记录的空格替换成',' 并希望得到数据如下,要有字段id和字段notext,谢谢。
------解决方案--------------------
--> 建立数据表#temp --数据表#temp里有'notext'字段记录
if object_id('tempdb.dbo.#temp') is not null drop table #temp
go
create table #temp([id] int,[notext] varchar(100))
insert #temp
select 2013099,'04 08 09 12 13 16 20 23 25 32 33'
--------------生成数据--------------------------
--> 测试数据
--楼主代码
select DISTINCT
stuff((select ','+''''+notext+'''' from #temp ORDER BY notext
for xml path('')),1,1,'') 'notext'
from #temp
drop table #temp
notext字段的结果是
'04 08 09 12 13 16 20 23 25 32 33'这不是楼主想要的
请问如何修改代码,如何把字段notext里记录的空格替换成',' 并希望得到数据如下,要有字段id和字段notext,谢谢。
id notext
2013099 '04','08','09','12','13','16','20','23','25','32','33'
------解决方案--------------------
if object_id('tempdb.dbo.#temp') is not null drop table #temp
go
create table #temp([id] int,[notext] varchar(100))
insert #temp
select 2013099,'04 08 09 12 13 16 20 23 25 32 33'
SELECT id,''''+REPLACE(''+notext+'',' ',''',''')+''''
FROM #temp
/*
id
----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2013099 '04','08','09','12','13','16','20','23','25','32','33'
*/