国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

解析Sqlserver常用函數

2024-08-31 00:46:59
字體:
來源:轉載
供稿:網友

在操作SQLServer的時候, 很多時候記不住具體的函數如何使用, 查找聯機幫助還是嫌麻煩, 且有很多時候例子也不好懂, 下面對每個常用的函數用用例子說明,一目了然,你自己在數據庫中執行一下,結果就知道什么回事了

--字符串功能
--substring
print substring('iamagoodperson',1,5)
select substring('iamagoodperson',1,5)

--upper
select upper('he is a good person')

--lower
select LOWER('this is an VERY interesting job')

--ltrim
select ltrim(' i am a good person')

--rtrim
select rtrim(' heihei,i do not know why it likes this ')


--replace
select replace('iwanttoaskyou','ttoa','i love you')

--stuff
select stuff('我的名字是朱旭杰',6,8,'summer')

--Date/Time Fuction
--getdate()
select getdate() as 'today'

--dateadd()
select dateadd(yy,10,getdate())

--datediff()
select datediff(yy,'1982/5/3',getdate()) as

--datepart()
select datepart(dw,getdate())
select datepart(yy,getdate())
select datepart(mm,getdate())
select datepart(dd,getdate())
select datepart(ss,getdate())
select datepart(ms,getdate())
select datepart(dd,'1982/5/3')
print datepart(dw,'1982/8/22')

--day(),相當于datepart(dd,時間)
select day('1982/5/3')
select day(getdate())

--month(),相當于datepart(mm,時間)
select month(getdate())

--year(),相當于datepart(yy,時間)
select year(getdate())

--數學函數

--abs()
select abs(-100.3456)

--sin()
select sin(0.54)

--cos()
select cos(3.14)

--power()
select power(10,2)

--round 返回數字表達式并四舍五入為指定的長度或精度


select round(100.45,1)
select round(123,45,-2)

--floor()
select floor(4.9)
select floor(-123.99)

--ceiling()
select ceiling(4.9)
select ceiling(-123.99)

--sqrt()
select sqrt(100)

--square
select square(10)
select square(-15)

--轉換函數
--cast()
select cast(100.45 as int)
select cast(1345 as varchar(10))

--convert()
select convert(int,100.56)
select convert(varchar(10),2345)

--空值函數
--isnull()
declare @temp_table table
(
bookID VARCHAR(10) primary key,
book_price float default null,
bookName varchar(50)
)
insert into @temp_table values('1',50,'c#')
insert into @temp_table values('2',null ,'c')
select bookID AS '書的編號',isnull(book_price,0) as '書的價格'
from @temp_table

--nullif(),只要參數里的兩個表達式相同就返回null
select nullif('iam','iam')

--coalesce返回其參數中第一個非空表達式
select coalesce(null,null,'i am a good boy')

 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金山区| 弋阳县| 比如县| 大安市| 炉霍县| 榆树市| 崇州市| 六盘水市| 平远县| 中超| 仲巴县| 城市| 铜陵市| 凌海市| 西林县| 黄浦区| 大同县| 黄冈市| 和顺县| 阳信县| 辉南县| 封开县| 隆回县| 巩义市| 柏乡县| 阆中市| 乌兰察布市| 略阳县| 荆门市| 阜新市| 建始县| 邢台市| 科技| 襄汾县| 南汇区| 鹿泉市| 马边| 襄樊市| 民丰县| 古浪县| 阳江市|