流程控制语句
If else语句
If (表。列)
{语句|语句块begin,,,end}
Else
{语句|语句块begin,,,end }
If else 语句嵌套
If
Begin
If
Else if
Else
End
Else
Select
Case (判断式)
When then
Else …
End
From
While 语句条件控制while语句中使用其他语句
延迟语句
Waitfor
{delay time|time}
Wait for delay ‘00:00:05’
Exec sp_help ----------时间间隔
Waitfor time ’21:00:00’
Exec sp_help ------------时间点
Goto跳转语句Lable
Try,,,catch错误处理语句
Begin try
容错error
End try
Begin catch
{}
End catch
数学函数
ABS | 绝对值 |
EXP | 以e为底指数 |
Ceiling | 退1法 |
floor | 进1法 |
Ln | 自然对数 |
log | 以10为底对数 |
power | 10power 2=102 |
round | 舍入到指定小数 |
sign | 返回 +- 0 |
square | 平方 |
aqrt | 平方根 |
字符串函数
ASCII | 返回代码的ASCI代码值 |
Char | 转换为字符 |
Left/right | 截取左/右指定个数 |
len | 字符串的格数 |
Lower/upper | 转换大写/小写 |
Ltim/rtrim | 删除头尾空格返回 |
Replace | 原串,将要被替换的串,替换用的串 |
space | 返回多个空格组成的字符串 |
str | 数值转字符串(串,开始,长度) |
substring | 子串函数,返回部分 |
特殊字符串函数
Charindex:子字符串出现的开始位置
Charindex(子串,父串) 【不可以是text/image】
Patindex(子串含通配符)【支持 char varchar text】
聚合函数
AVG |
|
COUNT | 影响行数 |
MAX |
|
MIN |
|
SUM |
|
日期和时间函数
Dateadd | 单位,时间,日期 |
Datediff | 单位,两个日期 |
Datename |
|
Datepart | Datepart(yy|dd|mm ,getdate) |
Day Month Year | Year(getdate()) |
Getdate | 当前系统时间 |
Getutcdate | UTC 时间 |
Create function 函数名(参数列表) create function 函数名 (参数列表)
Return (返回类型) return table
[with encryption] with encryption
[as] as
Begin return (表变量/数据表/查询结果)
函数体
End