SQL Server实现将特定字符串拆分并进行插入操作的方法
作者:Quber 时间:2024-01-21 04:48:31
本文实例讲述了SQL Server实现将特定字符串拆分并进行插入操作的方法。分享给大家供大家参考,具体如下:
--循环执行添加操作
declare @idx as int
While Len(@UserList) > 0
Begin
Set @idx = Charindex(',', @UserList);
--只有一条数据
If @idx = 0 and Len(@UserList) > 0
Begin
Insert Into BIS_MsgCenterInfo(ID,MsgID,UserID,[State])Values(Newid(),@ID,@UserList,0);
Break;
End
--多条数据
If @idx > 1
Begin
Insert Into BIS_MsgCenterInfo(ID,MsgID,UserID,[State]) Values(Newid(),@ID,left(@UserList, @idx - 1),0);
Set @UserList = right(@UserList, Len(@UserList) - @idx);
End
Else
Set @UserList = right(@UserList, Len(@UserList) - @idx);
End
希望本文所述对大家SQL Server数据库程序设计有所帮助。
标签:SQL,Server,字符串拆分,插入
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mysql 8.0.11安装配置方法图文教程
2024-01-27 17:22:08
![](https://img.aspxhome.com/file/2023/7/77217_0s.jpg)
python进阶教程之函数对象(函数也是对象)
2022-08-28 01:06:42
mysql数据库是做什么
2024-01-16 04:18:16
python中的lambda函数用法指南
2021-04-15 02:58:15
![](https://img.aspxhome.com/file/2023/0/134450_0s.jpg)
django 数据库返回queryset实现封装为字典
2024-01-20 15:43:43
Go语言基础模板设计模式示例详解
2024-02-01 16:29:32
![](https://img.aspxhome.com/file/2023/2/112232_0s.png)
ASP与MySQL的连接[图文教程]
2010-03-14 11:21:00
![](https://img.aspxhome.com/file/UploadPic/20093/9/200939182427439s.png)
Python中的asyncio代码详解
2022-03-14 00:01:33
python 实现客户端与服务端的通信
2023-11-19 01:28:33
![](https://img.aspxhome.com/file/2023/7/101207_0s.png)
thinkphp 多表 事务详解
2023-07-08 05:43:36
详解Python中使用base64模块来处理base64编码的方法
2022-01-12 01:27:19
sql server 交集,差集的用法详解
2024-01-23 03:44:08
![](https://img.aspxhome.com/file/2023/1/84361_0s.png)
Python通过PIL获取图片主要颜色并和颜色库进行对比的方法
2022-06-05 13:51:35
PHP的mysqli_select_db()函数讲解
2023-06-07 18:59:44
![](https://img.aspxhome.com/file/2023/8/55458_0s.png)
详细整理python 字符串(str)与列表(list)以及数组(array)之间的转换方法
2022-03-16 09:40:28
Python requests HTTP验证登录实现流程
2021-02-27 16:43:04
![](https://img.aspxhome.com/file/2023/7/75337_0s.png)
linux 部署apache服务的步骤
2022-11-28 02:59:16
如何解决python多种版本冲突问题
2023-12-28 06:41:17
![](https://img.aspxhome.com/file/2023/7/82557_0s.jpg)
Mysql 错误问题汇总(不断更新中)
2024-01-18 23:51:22
msxml3.dll 错误解决办法
2009-05-25 18:02:00