每天一点点(1)
--SQL函数******************************
--数学函数...
--abs 返回数值的绝对值:
select *from SC
where sno = '3130050106'update SC set score = abs(-90)
where sno = '3130050106'--ROUND函数
select
round(12345.34567,3) --精确到小数点后,12345.34600select
round(12345.34567,-3)--精确到小数点前,12000.00000
go
--字符串函数...
--substring函数
select * from sc
where cno = substring('sddc3',4,2)
--结果:
--3130050101 c3 97
--3130050102 c3 95
--3130050103 c3 97--replicate函数
select replicate('wuzang',3)
--wuzangwuzangwuzang
--日期和字符串函数...
--datepart 函数 ,getdate函数
select datepart(month,getdate()) as 当前月份
-- 8
select getdate() as 'wuzang'
--2011-08-19 10:14:52.670
--datediff函数 返回两个指定日期之间所跨的日期和时间边界的数目。
select datediff(month,'2006-03-24',getdate())
--65--用户定义函数
--例如:
create function TwoTimes
(@input int =0)
returns int
as
begin
return 2*@input
end
--使用:
select TwoTimes()