SQL SERVER 字符拆分列为多行
注:先学习sql server里的递归CTE。
假设有兴趣表Hobbys
| Name | Hobby |
| 小张 | 篮球,足球,羽毛球 |
| Name | Hobby |
| 小张 | 篮球 |
| 小张 | 足球 |
| 小张 | 羽毛球 |
采用【递归cte】
with tempHobbys as (select Name,Hobby,charindex(',',Hobby)-1 endindex,0 startindex from Hobbys
union all
select Name,Hobby,charindex(',',Hobby,endindex+2)-1 endindex,endindex+2 startindex from tempHobbys where endindex>-1),
with tempHobbys 2 as (select Name,Hobby,(case when endindex<0 then len(Hobby) else Hobby end) endindex,startindex from tempHobbys)
select Name,substring(Hobby,startindex,endindex-startindex+1) Hobby from tempHobbys2
SQL SERVER 字符拆分列为多行的更多相关文章
- MS SQL Server字符拆分函数
Insus.NET以前有用XQuery的nodes()方法写过一个函数,是MS SQL字符拆分的函数,http://www.cnblogs.com/insus/archive/2012/02/26/2 ...
- 查询sql server 2008所有表和行数
查询sql server 2008所有表和行数 SELECT a.name, b.rows FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.i ...
- sql server 字符数据类型
SQL Server 中字符类型包括varchar.char.text等.主要用于存储字符数据.varchar和char类型的主要区别在于数据填充.例如,一个列名为FirstName且数据类型为var ...
- SQL SERVER 拆分列为多行
--创建测试表 )) insert into #temp(names) values('张三,李四'), ('中国,美国,巴西'), ('深圳,上海,北京,广州,哈尔滨'), ('足球,篮球,乒乓球, ...
- (转)SQL Server 2008怎样编辑200行以上的数据
刚换SQL Server2008 不久,感觉运行速度.编辑提示都比05版的提升不少,但是在维护考试系统中遇到一个05中没有的问题:05中有“打开表”可以编辑所有数据行,到了08变成了“打开前1000行 ...
- SQL SERVER 中 实现主表1行记录,子表多行记录 整合成一条虚拟列
表中有这样的记录,简单的主子表,现要想通过left join 语句把两表关联起来 select * from tbl_diary_reback a left join tbl_diary_reback ...
- SQL Server遍历所有表统计行数
DECLARE CountTableRecords CURSOR READ_ONLY FOR SELECT sst.name, Schema_name(sst.schema_id) FROM sys. ...
- sql server update时,是行锁还是表锁
https://bbs.csdn.net/topics/120000749 http://www.cnblogs.com/s021368/articles/2148659.html 问题: udpat ...
- oracle,sql server count函数 存储过程 判断 行数 注意事项
oralce中使用 count 函数判断 行数 需要注意 一定是count 有值的字段,接下来看一组语句 --查询数据 select * from kk_create_ka where auto_id ...
随机推荐
- js动画(速度)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...
- 卸载linux系统上自带的mysql
步骤: 1.打开centos命令提示符,切换为root用户 2.输入rpm -qa|grep -i mysql命令以检查系统含有的mysql插件,回车,若没有则说明无自带mysql,系统很干净.若有显 ...
- C# 里调用vb的inputbox弹出窗
https://blog.csdn.net/hutao1101175783/article/details/16800871 先对项目添加对Microsoft.VisualBasic的引用 Inter ...
- C# winfrom 当前程序内存读取和控制
https://zhidao.baidu.com/question/31914620.html https://www.cnblogs.com/xcsn/p/4678322.html Process ...
- (转)Awesome Courses
Awesome Courses Introduction There is a lot of hidden treasure lying within university pages scatte ...
- Vim的一些使用
Vim的三种模式 normal(普通模式) insert(插入模式) command(命令模式) Vim的工作方式不同于常规的编辑器,在常规编辑器下对应到Vim中就是一直使用insert模式进行操作, ...
- Shiro学习笔记五(Shiro标签,及通配符)
1.首先是导入标签库 <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> ...
- Git-Flow | How it’s used and why you should
Git-Flow | How it’s used and why you should What is Git-Flow about? Git-Flow is a workflow for using ...
- Images之multi-stage builds
原文链接 Use multi-stage builds Multi-stage builds are a new feature requiring Docker 17.05 or higher on ...
- Linux 命令之sed
简介 sed 是一种在线编辑器,它一次处理一行内容.在处理的时候,会先把当前处理的行存储在临时缓冲区,这被称之为 "末世空间", 然后再使用 sed 命令处理缓冲区的内容,处理完成 ...