将字符串变量转换成临时表
来源:互联网 发布:icloud照片怎么导入mac 编辑:程序博客网 时间:2024/06/14 11:54
1.由于数据库中不存在数组,所以我们在需要使用数组时往往采用字符串加分割符的方式来间接表达数组,常用的形式如下:‘1001,1002,1003,100004,106,‘ 注意最后的逗号不能 省略,将用于判断字符串结束标志。
具体例子如下:
declare @vc_op_code varchar(8000), @vc_project_id varchar(8000), @l_left_index int, @l_right_index int select @vc_op_code = '1001,1002,1003,1004,1005,1006,',--加逗号保护 @vc_project_id = '2001,2002,2003,2004,', --加逗号保护 @l_left_index = 1, @l_right_index = 1 --存放柜员编号临时表create table #op_codes( l_op_code int default 0 )--存放项目编号临时表create table #project_ids( l_project_id int default 0)--生成柜员号表 while charindex(',',@vc_op_code,@l_left_index)<>0 begin select @l_right_index=charindex(',',@vc_op_code,@l_left_index) insert into #op_codes (l_op_code) values(SUBSTRING(@vc_op_code,@l_left_index,@l_right_index-@l_left_index)) set @l_left_index = @l_right_index+1 end set @l_left_index = 1 set @l_right_index = 1 --生成项目编号表while charindex(',',@vc_project_id,@l_left_index)<>0 begin select @l_right_index=charindex(',',@vc_project_id,@l_left_index) insert into #project_ids (l_project_id) values(SUBSTRING(@vc_project_id,@l_left_index,@l_right_index-@l_left_index)) set @l_left_index = @l_right_index+1 end select * from #op_codesselect * from #project_ids drop table #op_codesdrop table #project_ids
0 0
- 将字符串变量转换成临时表
- 将字符串转换成表
- 如何将其它类型的变量转换成字符串
- 将 _variant_t 类型的变量,转换成字符串
- 将字符串变量转换成UNICODE的函数
- 【6】python将字符串转换成变量(不可赋值)
- 将字符串变量转换为控件指针
- 将一个整型变量转换为字符串
- 将一个整型变量转换为字符串
- C++将整形变量转换为字符串
- 将字符串转换成表的形式
- sql server 将字符串转换成表
- 将”字符串和变量“组合成变量
- 将临时变量内联化 & 以查询代替临时变量
- 不用临时变量实现变量转换
- 将字符串中的.转换成/
- 将整数转换成字符串
- 将字符串转换成十六进制
- 面试题(一)
- spring-boot,jdbc,jsp配置
- 「改进的快速排序」时间复杂度接近O(n)
- XssSniper 扩展介绍
- ubuntu下tcpdump总结
- 将字符串变量转换成临时表
- Android软键盘强制弹出,隐藏输入法.
- json集合字符串转对象
- Python http 请求笔记
- Sping之Bean的生命周期
- JAVA中int与string互转的效率对比
- Java代理模式
- git生成ssh key及本地解决多个ssh key的问题
- JS 打开新窗口的方法