MID() 从文本字段中提取字符。
SELECT MID(City,1,3) as SmallCity FROM Persons
ROUND() 函数 数值字段舍入为指定的小数位数。
SELECT ROUND(column_name,decimals) FROM table_name
NOW() 函数 返回当前的日期和时间。
SELECT NOW() FROM table_name
FORMAT () 用于对字段的显示进行格式化。
select FORMAT(stu_intime,'yyyy-MM-dd hh:mm:ss') as intime from stu
SELECT INTO 从一个表中选取数据,然后把数据插入另一个表中。
select stu_name,stu_id into stu1 from stu --将stu表中的stu_id和stu_name插入新表stu1(会创建一个新表)
sql server 中没有limit 但是有top
/*查询 从n开始的m条数据 */ declare @n int=2; declare @m int = 5; select top (@m) * from stu where id not in (select top (@n) id from stu) /*查询n到m之间的数据*/ declare @n int=2; declare @m int = 5; select top (@m-@n+1) * from stu where id not in (select top (@n-1) id from stu)
BETWEEN … AND 会选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
/* 查询id 1 到3 的数据 */ select * from stu where id between '1' and '3'
ALTER TABLE 语句用于在已有的表中添加、修改或删除列。
alter table stu add stu_sj varchar(200) --添加一列名为stu_sj alter table stu drop column stu_sj --删除列
DISTINCT 用于返回唯一不同的值。
/* 返回名字,重复的不返回 */ select distinct stu_name from stu
到此这篇关于SQLServer之常用函数总结详解的文章就介绍到这了,更多相关SQLServer之常用函数内容请搜索
更多SQL内容来自木庄网络博客