[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[整理]SQL Server的T-SQL的一点学习笔记

上一篇:[整理]测试ASP使用SA FileUp组件上传的一小段代码。
下一篇:[转]英语的电话用语

添加日期:2008/3/4 14:50:53 快速返回   返回列表 阅读4250次
if ...
else ...
------------------------------
if ...
    begin 
        ...
    end
else
    begin
        ...
    end
--------------------------------------
declare @count int
select @count=1
while(@count<10)
    begin
        select @count=@count+1
        print @count
    end
----------------------------------------
while循环支持break和continue。
没有For循环。
----------------------------------------
GOTO Label:
...
Label:
----------------------------------------
declare @name nvarchar(30),@type int
赋值之前为NULL
select @name='xxx',@type=123
select @name=Max(name) from user

@@虽然叫全局变量,但其实只是当前用户会话的信息
@@rowcount    前一条命令处理的行数
@@error 前一个sql的错误号,如果<>0,说明出错了。
@@trancount    事务嵌套的级别
@@transtate 事务当前的状态
@@tranchained    当前事务的模式(链接或非链接的)
@@servername    本地SQL Server的名称
@@spid        当前进程ID
@@identity    上次insert操作使用的identity值。
@@nestlevle    存储过程/触发器中的嵌套层,初始为0,一个存储过程调用另一个时,就增加。
@@fetch_status    游标中上条fetch语句的状态,0成功,-1失败,-2没有数据
----------------------------------------------------
WaitFor语句用户使查询在某时刻或者一段时间间隔后继续执行。
不能指定日期,时间长度不能超过24小时。
WaitFor time "22:00:00" 22点执行
WatiFor delay "0:00:30" 等待30秒
----------------------------------------------------
RaisError
----------------------------------------------------
SET rowcount 100 只返回数据的前100行
SET statistics time on 显示执行时间
SET nocount on 不汇报返回的行数
------------------------------------------------------
datalength(xx) 字符个数,不包括尾部空格
substring(xx,1,3) 1开始的3个字符
right(xx,3)右边3个字符
upper(xx)
lower(xx)
space(10) 10个空格
replicate('a',10) 10个a
stuff(xx,1,10,yy) 从1开始的10个字符删除,删除处插入yy
reverse(xx) 反转
ltrim(xx)
rtrim(xx)

ascii(char) 返回首个字符的ascii值
char(int) ascii码转换为字符
str(float) 数字型转换为字符
soundex(char) 返回字符串的soundex值

charindex(exp1,exp2,start)返回exp1在exp2种的起始位置
patindex('%pattern%',exp) 返回指定表达式中模式第一次出现的起始位置
---------------------------------------------------
乘方运算使用power()函数
select power(2.000000000,0.5) 返回1.414213....
返回类型与第一个参数一样。

declare @base numeric(14,9)
select @base=2
select power(@base,0.5)
-------------------------------------------------
isnull(xx,0)
nullif(xx,-1) 如果xx=-1当作null,如avg(nullif(price,-1))
-------------------------------------------------
select coalesce(homephone,workphone) ..
返回第一个非空的表达式
-------------------------------------------------
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved