拆分字符串,并存入临时表中
2005-12-14 16:38
148 查看
create table #mytable(account nvarchar(10))
declare @oldstring as nvarchar(3000)
declare @tempstring as nvarchar(10)
set @oldstring='10302299,10311441,10312196,10300104,10300297,10300381,10300509,10300564,10300679,10300732,10300743,10301331,10301338,10301359,10301414,10301785,10301787,10301910,10302121,10302160,10302220,10302269,10302983,10303821,10303913,10304481,10304659,10304671,10304680,10304691,10304698,10305624,10306061,10306815,10311833,10312241,10313045,10313120,'
while (PATINDEX('%,%',@oldstring)<>0)
begin
set @tempstring=substring(@oldstring,1,PATINDEX('%,%',@oldstring)-1)
insert into #mytable (account) values (@tempstring)--插入到临时表
set @oldstring=substring(@oldstring,PATINDEX('%,%',@oldstring)+1,len(@oldstring))
end
select * from #mytable
declare @oldstring as nvarchar(3000)
declare @tempstring as nvarchar(10)
set @oldstring='10302299,10311441,10312196,10300104,10300297,10300381,10300509,10300564,10300679,10300732,10300743,10301331,10301338,10301359,10301414,10301785,10301787,10301910,10302121,10302160,10302220,10302269,10302983,10303821,10303913,10304481,10304659,10304671,10304680,10304691,10304698,10305624,10306061,10306815,10311833,10312241,10313045,10313120,'
while (PATINDEX('%,%',@oldstring)<>0)
begin
set @tempstring=substring(@oldstring,1,PATINDEX('%,%',@oldstring)-1)
insert into #mytable (account) values (@tempstring)--插入到临时表
set @oldstring=substring(@oldstring,PATINDEX('%,%',@oldstring)+1,len(@oldstring))
end
select * from #mytable
相关文章推荐
- SQLServer2008运用存储过程拆分字符串并查询结果并把结果存入临时表中。
- 1.2 拆分字符串,存入数组
- 把一个字符串分开存入一个临时表中
- sqlserver以逗号分割的字符串拆分到临时表
- sql 将逗号分割的字符串存入临时表
- 拆分字符串
- 【叶子函数分享三十六】SQL2000/2005字符串拆分为列表通用函数
- 【SQL】sql版Split函数。用于拆分字符串为单列表格
- SQLServer利用表值函数拆分字符串一例分析
- 循环拆分带有字符的字符串
- 实验十(二)-1、输入一个字符串和一个正整数x,将该字符串中的后x个字符复制到另一个字符串y中,输出字符串y;再对y串的内容前后倒置后存入数组z中并输出。
- 面试:不开辟用于交换数据的临时空间,如何完成字符串的逆序
- 使用正则表达式(组的概念/拆分字符串)
- sqlserver字符串拆分(split)方法汇总
- [导入]循环拆分带有字符的字符串
- T-SQL技巧收集——拆分字符串
- oracle 拆分字符串并转换为表
- Shell 字符串拆分成数组
- ABAP中拆分字符串到内表,然后再遍历的实现方法
- 把参数字符串中的字符反向排列(不使用数组和库函数操作字符串的函数,不要局部数组来临时存储参数字符串)