这样的字符串(aa,bb,cc,dd)怎么批量插入成4条记录到数据表里呢

rehearts 2006-08-29 06:23:24
谢谢
...全文
178 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuehaiyang 2006-08-29
  • 打赏
  • 举报
回复
函数或存储过程,先分割,然后插入
rehearts 2006-08-29
  • 打赏
  • 举报
回复
谢谢各位 我先测试下
specialsoldier 2006-08-29
  • 打赏
  • 举报
回复
create proc proc_split_str(@param varchar(100))
as
BEGIN
DECLARE @temp varchar(100)
set @temp=''
while charindex(',',@param)>0
begin
SELECT @temp=left(@param,charindex(',',@param)-1)
set @param=stuff(@param,1,charindex(',',@param),'')
select @temp
--insert into test select @temp
end
--insert into test select @temp
select @param
END

exec proc_split_str 'aa,bb,cc,dd'

到时候只要按照你的表模型将select换成insert语句就可以了
WangZWang 2006-08-29
  • 打赏
  • 举报
回复
--如:
declare @s varchar(8000)
set @s='aa,bb,cc,dd'

select @s=replace(@s,',',''' as ID union all select ''')

exec('
Insert into 表(列)
select '''+@s+'''')
xyxfly 2006-08-29
  • 打赏
  • 举报
回复
写个函数吧

34,590

社区成员

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

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