SQL Server常用的函数.docx_第1页
SQL Server常用的函数.docx_第2页
SQL Server常用的函数.docx_第3页
SQL Server常用的函数.docx_第4页
SQL Server常用的函数.docx_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

字符串函数1. charindex();用来寻找一个指定的字符串在另一个字符串中的起始位置Example:select charindex(name,my name is tom,1); return: 4 2. len();返回传递给他的字符串长度 Example:select len(课程); return: 123. upper();把传递给它的字符串转换为大写 Example:select upper(sql server教程); return:SQL SERVER教程4. lower();把传递给它的字符串转换为小写Example:select upper(SQL SERVER教程); return:sql server教程5. ltrim();清除字符左边的空格Example:select ltrim( sqlserver ); return:sqlserver ;(后面的空格保留);6. rtrim();清除字符右边的空格Example:select ltrim( sqlserver ); return: sqlserver;(前面的空格保留);7. right();从字符串右边返回指定数目的字符Example:select right(买买提.吐尔松,3); return:吐尔松8. left();从字符串左边返回指定数目的字符Example:select left(买买提.吐尔松,3); return:买买提9. replace(); 替换一个字符串中的字符Example:select replace(磨了刻单反,单,课); return:磨了刻课反10. stuff(); 在一个字符串中,删除指定长度的字符,并在该位置插入一个新的字符串Example:select stuff(ABCDEF,2,3,我的音乐我的世界);说明:2是位置,3是长度 return:A我的音乐我的世界EF日期函数1. getdate(); 取得当前系统的时间 Example:select getdate(); return:当前的系统时间2. dateadd(); 将指定的数值添加到指定的日期部分后的日期Exmapl:select dateadd(mm,4,2009-01-01);return:2009-05-013. datediff(); 两个日期之间的指定日期部分的间隔Example:select datediff(mm,2009-01-01,2009-10-01);return:94. datename(); 日期中指定日期部分的字符串形式Example:select datename (dw,2009-01-01); return:星期四5. datepart(); 日期中指定日期部分的整数形式Example:select datepart(day,2009-01-15); return:15日期的部分参数及缩写日期的参数缩写1. year 年yy,yyyy2.quarter一刻钟即15分钟qq,q3.month月份mm,m4.dayofyear积日dy,y5.day一天dd,d6.week周wk,ww7.weekday平日dw,w8.hour小时hh9.minute分钟mi,n10.second秒ss,lisecond毫秒ms数学函数1. rand(); 返回从0到1之间的随机float值Example:select rand(); return:0.1254562.abs();取数值表达式的绝对值Example:select abs(-43); return:433.ceiling(); 向上取整,取大于或等于指定数值、表达式的最小整数 Example:select ceiling(43.5); return:444. floor(); 向下取整,取小于或等于指定数值、表达式的最大整数 Example:select floor(43.5); return:435. power(); 取数值表达式的幂值 Example:select power(8,2); return:646. round(); 将数值表达式四舍五入为指定精度Example:select round(43.543,1); return:43.500 注意:第二个参数是小数点后几位 如果round(43.543,0); return:447. sign(); 对于正数返回+1,对于负数返回-1,对于0则返回0Example:select sign(-43); return:-1;select sign(44); return:1;select sign(0); return:0;8. sqrt(); 取浮点表达式的平方根Example:select sqrt(9); return:3系统函数1. convert(); 用来转变数据类型Example:select convert(varchar(5),12345); return:字符串123452. current_user 返回当前用户的名字Example:select current_user; return:你登录的用户名3. datalength(); 返回用于指定表达式的字节数Example:select datalength(中国A联盟); return:94. host_name(); 返回当前用户所登录的计算机名字Example:select host_name(); return:你所登录的计算机名字5. system_user; 返回当前你登录SQL Server的用户名Example:select system_user; return:登录SQL Server的用户名6. user_name; 从给定的用户ID返回用户名Example:select user_name(1); return:从任意数据库返回“dbo”聚合函数(对null不统计)下面的例子用到这个表1. sum(); 返回表达式中所有数值的总和,当是只能用于数字类型的列,不能用于汇总字符、日期等其他类型Example:select sum(StudentResult) from Result; return:10742. avg(); 返回表达式中所有数值的平均值,也只能用于数字类型的列Example:select avg(StudentResult) from Result; return:71 3. max()和min(); max()返回表达式中的最大值,min()返回表达式中的最小值,他们都可以用于数字型、字符型以及日期/时间类型的列Example:select max(StudentResult) from Result; return: 90select min(StudentResult) from Result; return: 504. count(); 返回提供的组或记录集中的计数,可用于数字和字符类型的列。也可用星号count(*)作为count的表达式,使用星号可以不必指定特定的列而计算所有行数Example:select count(*) from Result where StudentResult = 60 ; return:125. stdev(); 函数根据数据母体的样本返回由表达式提供的所有值的标准差Example:select STDEV(StudentResult) from Result return 13.3833585.6. stdevp(); 函数也返回由表达式提供的所有值的标准差,只是它计算整个数据母体Example:select STDEVP(StudentResult) from Result return 12.92955.7. var(); 函数根据数据母体的样

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论