这个存储过程怎么写

jinchun 2003-03-26 12:07:18
将字符串 a,b,c 分别插入表中为三行,值分别为a b c
我该怎么写,能分离成数组吗?怎么写
...全文
31 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CrazyFor 2003-03-26
  • 打赏
  • 举报
回复
OR:

declare @str varchar(1000),@strSQL Varchar(2000)
set @str='a,b,c,d'
set @strSQL='select '''+replace(@str,',',''' union all select ''')+''''
print @strSQL
exec(@strSQL)
CrazyFor 2003-03-26
  • 打赏
  • 举报
回复
参考:

J9988提供

drop table #temp
select top 1000 identity(int,1,1) as col,0 aa into #temp from
(select top 100 * from sysobjects)a,
(select top 100 * from sysobjects)b,
(select top 100 * from sysobjects)c


declare @a table (id int,string varchar(8000))
insert @a select 1 ,'a,b,c,sd,dfsdfg'
union select 2, 'a,n,sdf,we,t'
union select 3, 's,df,df'

select id,substring(','+string+',',col+1,charindex(',',','+string+',',col+1)-(col+1))
from @a a,#temp b
where len(string+',')-len(replace(string,',',''))>=b.col
order by id

tmj 2003-03-26
  • 打赏
  • 举报
回复
up

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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