解析Sqlserver常用函數(shù)_Mssql數(shù)據(jù)庫教程
推薦:觸發(fā)器學(xué)習(xí)觸發(fā)器是一種特殊的存儲過程,類似于其它編程語言中的事件函數(shù),SQL Server 允許為 INSERT、UPDATE、DELETE 創(chuàng)建觸發(fā)器,當在表(視圖)中插入、更新、刪除記錄時,觸發(fā)一個或一系列 T-SQL 語句。 1: 創(chuàng)建觸發(fā)器 : 觸發(fā)器可以在企業(yè)管理器里創(chuàng)建,也可以在
在操作SQLServer的時候, 很多時候記不住具體的函數(shù)如何使用, 查找聯(lián)機幫助還是嫌麻煩, 且有很多時候例子也不好懂, 下面對每個常用的函數(shù)用用例子說明,一目了然,你自己在數(shù)據(jù)庫中執(zhí)行一下,結(jié)果就知道什么回事了
--字符串功能
--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())
--數(shù)學(xué)函數(shù)
--abs()
select abs(-100.3456)
--sin()
select sin(0.54)
--cos()
select cos(3.14)
--power()
select power(10,2)
--round 返回數(shù)字表達式并四舍五入為指定的長度或精度
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)
--轉(zhuǎn)換函數(shù)
--cast()
select cast(100.45 as int)
select cast(1345 as varchar(10))
--convert()
select convert(int,100.56)
select convert(varchar(10),2345)
--空值函數(shù)
--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(),只要參數(shù)里的兩個表達式相同就返回null
select nullif('iam','iam')
--coalesce返回其參數(shù)中第一個非空表達式
select coalesce(null,null,'i am a good boy')
分享:SQL SERVER數(shù)據(jù)庫開發(fā)之存儲過程應(yīng)用由于個人能力有限,文章中難免會出現(xiàn)錯誤或遺漏的地方,敬請諒解!同時歡迎你指出,以便我能及時修改,以免誤導(dǎo)下一個看官。最后希望本文能給你帶來一定的幫助。 可能有不少朋友使用SQL SERVER做開發(fā)也已經(jīng)有段日子,但還沒有或者很少在項目中使用存儲過程,
- sql 語句練習(xí)與答案
- 深入C++ string.find()函數(shù)的用法總結(jié)
- SQL Server中刪除重復(fù)數(shù)據(jù)的幾個方法
- sql刪除重復(fù)數(shù)據(jù)的詳細方法
- SQL SERVER 2000安裝教程圖文詳解
- 使用sql server management studio 2008 無法查看數(shù)據(jù)庫,提示 無法為該請求檢索數(shù)據(jù) 錯誤916解決方法
- SQLServer日志清空語句(sql2000,sql2005,sql2008)
- Sql Server 2008完全卸載方法(其他版本類似)
- sql server 2008 不允許保存更改,您所做的更改要求刪除并重新創(chuàng)建以下表
- SQL Server 2008 清空刪除日志文件(瞬間日志變幾M)
- Win7系統(tǒng)安裝MySQL5.5.21圖解教程
- 將DataTable作為存儲過程參數(shù)的用法實例詳解
- 相關(guān)鏈接:
- 教程說明:
Mssql數(shù)據(jù)庫教程-解析Sqlserver常用函數(shù)
。