1,IsNull函数,Cast函数
IsNull(<要检查的表达式>,<如果为null时替换的值>)
Cast(<要转换的表达式> as <转换成的数据类型>)
select tb_orderdetail.*,IsNull(
Cast((select min(OrderDate) From tb_orders Where tb_orders.id = tb_orderdetail.OrderId) as Varchar),'neverordered')
as OrderDate From tb_orderdetail
2--Convert函数
--Convert(数据类型,表达式[,格式])
--这个函数和Cast类似
select OrderDate,Convert(Varchar(23),OrderDate,121) as Convered From tb_orders Where CustomerId =25
--日期格式:http://msdn.microsoft.com/en-us/library/ms187928.aspx
3,--Exists函数
--返回数据是否存在的布尔变量
--表1,tb_employee,表2,tb_contact,表3,tb_hrdepart
select e.EmployeeId,FirstName,LastName,From tb_employee e join tb_contact c on e.ContactId = c.ContactId
where exists(
select EmployeeId From tb_hrdepart hr where hr.EmployeeId = e.EmployeeId
)
--找出人事部门员工的用户信息
use master
go
if not exists (select 'True' From sys.databases where name = 'newdb')
begin
create database newdb
end
else
begin
print 'newdb is exist'
end
go
4,--Floor函数
--获取提供的值,把它取整到最近的整数上
--declare @myval decimal(15,3); --这个计算比较数确用于做账
declare @myval int;
--declare @myval real;
--declare @myval float;
set @myval = 3.6;
set @myval = @myval * 2;
select @myval;
select floor(@myval)+.9 as mycolumn
5,--系统默认变量
COALESCE
coalesce哪个不为空用哪个
@@Datefirst
系统认为星期几是一周的第几天,返回这个数字
@@Error
返回错误号,没有错误返回0
@@cursor_rows
返回游标中的行数
@@fetch_status
返回最后一个游标fetch操作状态的指示值
0成功
-1失败,超过了游标的尾
-2失败,当前记录被删除,发生在滚动游标和动态游标上
@@identity
返回当前连接创建的最后一行记录的标志
@@rowcount
返回上一条语句影响的行数

浙公网安备 33010602011771号