函数
来源:互联网 发布:sql语言怎么查询数据 编辑:程序博客网 时间:2024/06/05 19:47
一、去除空格函数:
rtrim(’ ‘),可以传递字符串,常量,变量,去除右边空格,括号内可以是目标字符串、常量、变量、。。。
ltrim(’ ‘), 去除左边空格
rtrim(’ ‘), 去除右边空格
select rtrim(' 百度 网址 www.baidu.com ') as newtitle;select ltrim(' 百度 网址 www.baidu.com ') as newtitle;
二、截取字符串长度
SUBSTRING(’字符串 ‘,从第几个字符开始,截取的长度)
select SUBSTRING('夜鹰教程网的网址是www.yyjcw.com/tuangou.html',2,7) as title;输出结果:鹰教程网的网址
三、在字符串中插入另一个字符串
1、select STUFF('北京高科网址www.bjdsst.com',3,0,'鼎晟') as title 输出结果:北京鼎晟高科网址www.bjdsst.com,插入鼎晟,不替换原有内容2、select STUFF('北京高科网址www.bjdsst.com',3,2,'鼎晟') as title 输出结果:北京鼎晟网址www.bjdsst.com,从第三个字符开始,替换两个字符
北京高科网址www.bjdsst.com:可以使用变量代替
四、显示字符串长度函数
declare @websit nvarchar(50)set @websit='123456798zhongsb'select len(@websit) as title
五、大小写转换
select LOWER (‘字符串’) as 字段名 —— 转变为小写
select upper (字符串’) as 字段名 —— 转变为大写
select LOWER('asdasfsdfSDFGDFGsdfgdfgsdfgs') as t;select upper('asdasfsdfSDFGDFGsdfgdfgsdfgs') as t;select *,lower(EnName) as newName from Students;select *,upper(EnName) as newName from Students;
六、替换字符串中的特殊符号
select replace(‘sdfgsdf 夜鹰教程网 硅谷动力网 网易门户 网 aassdsfgsdfg ‘,’网’,’ ‘);
select replace(‘sdfgsdf 夜鹰教程网 硅谷动力网 网易门户 网 aassdsfgsdfg ‘,’网’,’**’);
七、返回字符串中某个字符的位置
第三行输出结果:0281
八、时间函数
2、查询今天是星期几
select DATENAME(DW,GETDATE() ) as; ——今天是星期几
select DATENAME(WW,’2012-05-05’) as; 是一年中的第几周
3、
4、计算两个日期之间的天数:函数DATADIFF(d,’2012-05-06’,’2015-05-08’)
5、删除入学年份超过3年的同学
delete from Students where DATADIFF(YY,EnTime,GETDATE())>3;
6、常用缩写
7、dateadd函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 关于mathematica中添加注释的一些方法
- Java面向对象的三大特性之--《继承》
- 杭电3065(HDU3065)
- 40和的组合第二弹
- RecyclerView的安装包和source
- 函数
- POJ 1321 棋盘问题
- Bean的属性注入——为不同类型属性注值
- BZOJ 1797: [Ahoi2009]Mincut 最小割 图的联通 最小割 tarjan
- springboot + mybatis 多数据源最简解决方案
- 思维导图:一张图了解jQuery
- 个人理解tensor或多维数组的最佳方式
- Ubuntu 16.04配置Shadowsocks和Privoxy实现浏览器和终端代理
- 性能测试笔记--自己总结