sql 字段内容转换显示语句

icemanpro 2010-01-12 04:36:32
现有一字段A,其内容为123-412-asd,123-33-31
现想在select 时,将其内容转换成
'123-412-asd','123-33-31'

有什么语句可以达到?
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
SQL77 2010-01-12
  • 打赏
  • 举报
回复
DECLARE @S NVARCHAR(50)
SET @S='123-412-asd,123-33-31'
SELECT PARSENAME(REPLACE(@S,',','.'),1),
PARSENAME(REPLACE(@S,',','.'),2)



-------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------
123-33-31 123-412-asd

(所影响的行数为 1 行)
yananguo_1985 2010-01-12
  • 打赏
  • 举报
回复
select left([Col],charindex(',',[Col])-1),substring([Col],charindex(',',[Col])+1,len([Col])) from [table]
ws_hgo 2010-01-12
  • 打赏
  • 举报
回复
一句话
太快啦
SQL77 2010-01-12
  • 打赏
  • 举报
回复
DECLARE @S NVARCHAR(400)
SET @S='123-412-asd,123-33-31'
SELECT REPLACE(''''+@S+'''',',',''',''')

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'123-412-asd','123-33-31'

(所影响的行数为 1 行)
ws_hgo 2010-01-12
  • 打赏
  • 举报
回复
declare @str nvarchar(100)
set @str='123-412-asd,123-33-31'
select substring(@str,0,charindex(',',@str))+','+substring(@str,charindex(',',@str)+1,len(@str)-charindex(',',@str))
xiequan2 2010-01-12
  • 打赏
  • 举报
回复

declare @s varchar(1000)
set @s='123-412-asd,123-33-31'


select replace(''''+@s+'''',',',''',''')

/*
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'123-412-asd','123-33-31'
*/
dawugui 2010-01-12
  • 打赏
  • 举报
回复
create table tb(A varchar(50))
insert into tb values('123-412-asd,123-33-31')
go

select c1 = left(a , charindex(',',a) - 1),
c2 = substring(a , charindex(',',a) + 1 ,len(a))
from tb
where charindex(',',a) > 0


drop table tb

/*
c1 c2
-------------------------------------------------- --------------------------------------------------
123-412-asd 123-33-31

(所影响的行数为 1 行)


*/
快乐_石头 2010-01-12
  • 打赏
  • 举报
回复
declare @s varchar(50)
set @s='123-412-asd,123-33-31 '
select ''''+replace(@s,',',''',''')+''''
/*
'123-412-asd','123-33-31 '

(1 個資料列受到影響)

*/
dawugui 2010-01-12
  • 打赏
  • 举报
回复
分成两段?

select left(a , charindex(',',a) - 1),
substring(a , charindex(',',a) + 1 ,len(a))
from tb

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧