sql里的函数

上传人:飞*** 文档编号:2569934 上传时间:2017-07-25 格式:DOC 页数:3 大小:44KB
返回 下载 相关 举报
sql里的函数_第1页
第1页 / 共3页
sql里的函数_第2页
第2页 / 共3页
sql里的函数_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《sql里的函数》由会员分享,可在线阅读,更多相关《sql里的函数(3页珍藏版)》请在金锄头文库上搜索。

1、 sql 里的函数ISNULL 函数isnull( ,)CAST 函数cast( as )看例子select c.LastName,isnull( cast( select min(OrderDate) from Sales.SalesOrderHeader o where o.ContactID = c.ContactID) as varchar),neverordered) as orderdatefrom Person.Contact c再看一个例子:use AdventureWorksselect the order num is + Cast(SalesOrderID as varc

2、har) as xlandfrom Sales.SalesOrderHeaderwhere CustomerID = 5CONVERT 函数convert(数据类型,表达式, 格式)这个函数和 cast 类似,我们先看 cast 的一个例子use AdventureWorksselect OrderDate, Cast(OrderDate as varchar) as Converdfrom Sales.SalesOrderHeaderwhere CustomerID = 5再看 convert 的例子use AdventureWorksselect OrderDate, convert(va

3、rchar(12), OrderDate,111) as Converdfrom Sales.SalesOrderHeaderwhere CustomerID = 5这里对日期的格式做了限制具体这么限制要查 convert 的微软帮助文件EXISTS 函数先看例子返回数据是否存在的布尔变量use AdventureWorksselect e.EmployeeID,FirstName,LastNamefrom HumanResources.Employee ejoin Person.Contact con e.ContactID = c.ContactIDwhere exists(select

4、EmployeeID from HumanResources.JobCandidate jcwhere jc.EmployeeID = e.EmployeeID)这个例子也可以完成相同的功能use AdventureWorksselect distinct e.EmployeeID ,FirstName,LastNamefrom HumanResources.Employee ejoin Person.Contact con e.ContactID = c.ContactIDjoin HumanResources.JobCandidate jcon jc.EmployeeID = e.Empl

5、oyeeID第一个例子比第二个例子在性能上要好很多第三个用 exists 的例子use mastergo if not exists (select True From sys.databases where name = xland)begincreate database xlandend elsebeginprint xland is existend go在这里将看到 if else 和 begin end 的用法FLOOR获取提供的值,把他取整到最近的整数上declare myval int;set myval = 3.6;set myval = myval * 4.8;select floor(myval)+.9 as mycoloumnCOALESCEcoalesce 哪个不为空用哪个 COALESCE(i.ProductID,d.ProductID)Datefirst系统认为星期几是一周的第几天,返回这个数字Error返回错误号,没有错误返回 0cursor_rows返回游标中的行数fetch_status返回最后一个游标 fetch 操作状态的指示值0 成功-1 失败,超过了游标的尾-2 失败,当前记录被删除 ,发生在滚动游标和动态游标上identity返回当前连接创建的最后一行记录的标志rowcount返回上一条语句影响的行数

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号