SqlServer 2005 中字符函数的应用
时间:2024-01-16 09:01:32
USE Demo
GO
/*
将表Code的列String中的值提取放到Record表中
String 中字符类型为
dsddddd,2222222,222221,3
其中最后一位为标记对于Record表中的BiaoJi
前面的以','分割的是值对应Record表中Value
*/
GO
DROP PROC proc_split_Code
GO
CREATE PROC proc_split_Code
AS
BEGIN
SET NOCOUNT ON
DECLARE @Count INT --条数
DECLARE @Index INT --变量
SET @Index = 1 --默认
SELECT @Count = Count(*) FROM Code
--PRINT @Count
WHILE (@Index<=@Count)
BEGIN
DECLARE @BiaoJi INT -- 标记
DECLARE @String NVARCHAR(1000)--字符串
DECLARE @Temp INT --分隔符的位置
DECLARE @Star INT --开始位置
DECLARE @Code NVARCHAR(100) --
SET @Star = 0
SELECT @String=REVERSE(String)
FROM (
SELECT row_number() OVER(ORDER BY String) AS rownumber,* FROM Code
) AS a
WHERE rownumber between @Index and @Index
SET @Temp=CHARINDEX(',',@String,@Star)
SET @BiaoJi = SUBSTRING(@String,@Star,@Temp)
PRINT @BiaoJi
SET @String = REVERSE(@String)
SET @Temp=CHARINDEX(',',@String,@Star)
SET @Star = 0
WHILE(@Temp>0)
BEGIN
SET @Temp=CHARINDEX(',',@String,@Star)
--PRINT @Star
--PRINT @Temp
IF @Temp >0
BEGIN
SET @Code=SUBSTRING(@String,@Star,@Temp-@Star)
PRINT @Code
--插入到相应的表中
INSERT INTO Record(BiaoJi,Value,Time)
VALUES (@BiaoJi,@Code,getdate())
END
SET @Star=@Temp+1
END
--PRINT @Index
PRINT @String
SET @Index = @Index+1
END
END
GO
EXEC proc_split_Code
标签:SqlServer,字符函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
童年回忆录之python版4399吃豆豆小游戏
2021-04-30 18:52:44
![](https://img.aspxhome.com/file/2023/7/76717_0s.jpg)
pandas 读取各种格式文件的方法
2023-12-14 22:08:59
python实现超级玛丽游戏
2023-10-02 20:19:28
![](https://img.aspxhome.com/file/2023/9/99299_0s.gif)
Appium+Python自动化测试之运行App程序示例
2023-07-29 01:54:20
![](https://img.aspxhome.com/file/2023/6/60986_0s.jpg)
JavaScript中函数表达式和函数声明及函数声明与函数表达式的不同
2024-04-19 10:02:23
python3 自动识别usb连接状态,即对usb重连的判断方法
2022-03-10 01:26:21
PyQt5 在QListWidget自定义Item的操作
2023-07-05 16:35:49
![](https://img.aspxhome.com/file/2023/0/70750_0s.jpg)
Python中利用xpath解析HTML的方法
2023-10-02 06:55:02
Python利用memory_profiler查看内存占用情况
2022-05-24 08:55:29
![](https://img.aspxhome.com/file/2023/0/81810_0s.png)
mysql设置某字段不能重复问题
2024-01-19 19:22:14
![](https://img.aspxhome.com/file/2023/9/69259_0s.png)
Python可变与不可变数据和深拷贝与浅拷贝
2022-06-05 21:14:51
实例:arguments.callee的应用
2009-04-20 12:38:00
django框架CSRF防护原理与用法分析
2022-02-16 09:37:11
![](https://img.aspxhome.com/file/2023/0/83920_0s.png)
JavaScript中.min.js和.js文件的区别讲解
2024-04-30 09:56:19
python将文本转换成图片输出的方法
2023-06-20 11:47:47
sqlserver 数据库连接字符串中的可选项收集
2024-01-16 17:47:31
sqlserver 动态创建临时表的语句分享
2012-01-29 17:54:37
用Dreamweaver MX设计各种网页鼠标样式
2008-10-04 10:18:00
Python使用Web框架Flask开发项目
2021-07-08 20:08:56
数据库查询的分页优化技巧
2009-05-17 10:31:00