SQL函数

1、stuff函数

update aa set Code = stuff(Code,3,0,'2')

解析:aa为表名,Code为列名,3代表我要插入或删除字符的位置,0代表我要删除的字符个数,'2'代表我插入的字符。 

2、N

select * from aa where Name=N'李四'

解析:遇到取数出现乱码,可在字符串前方加N,规整字符串。

3、concat函数

select concat(Name,ID)from aa

解析:concat函数 会把两列字符拼接成一列字符串返回

 4、first函数

 select first(Name)from aa

解析:first函数会把Name列的第一个值返回。可使用 ORDER BY 语句对记录进行排序。

5、last函数

select last(Name)from aa

解析: last函数会把Name列的最后一个值返回。可使用 ORDER BY 语句对记录进行排序。

6、ucase函数和lcase函数

select ucase(Name)from aa

解析: ucase函数会把Name列含有英文小写字母转换为大写,lcase函数把大写转换为小写。

7、substring函数

select  substring(Name,2,1)from aa

解析:substring函数会从列字符串的位置2截取出1个字符,之前听说Mid也可,试了下SQL Server没有这个内置函数,不过substring函数也能实现截取字符串。

8、rtrim函数

select 'a ',rtrim('a '),'b '+'123',rtrim('a ')+'123'

执行结果:

解析:返回时会删除字符串右边的空格后的字符串

后续慢慢添加...............

原文地址:https://www.cnblogs.com/tao-1/p/10130872.html