SQL 常用函数

--时间函数:

SELECT DATEADD(YEAR,10,GETDATE())

select DATEDIFF(year,getdate(),getdate())

SELECT DATENAME(month,GETDATE())

SELECT DATEPART(MONTH,GETDATE())

SELECT DAY(GETDATE())

SELECT GETDATE()

SELECT GETUTCDATE()

SELECT MONTH(GETDATE())

SELECT YEAR(GETDATE())



--数学运算函数:

SELECT ABS(CONVERT(INT,-123548545))

SELECT FLOOR(1.12)

SELECT CEILING(1.12)

SELECT PI()

SELECT POWER(100,-1)

SELECT RAND(0.12)

SELECT ROUND(1.254,1)



--字符串函数:    

SELECT ASCII('A')

SELECT CHAR(65)

SELECT CHARINDEX('ik','MIKE')

SELECT LEFT('MIKE',2)

SELECT LEN('MIKE ')

SELECT LOWER('miKE')

SELECT LTRIM(' MIKE')

SELECT NCHAR('97')

SELECT PATINDEX('%CH%','mikechang')

SELECT REPLACE('MIKECHANG','ch','SPRIT')

SELECT len(REPLICATE('mi',10))

SELECT REVERSE('mikesoft')

SELECT RIGHT('MIKESOFT',3)

SELECT RTRIM('MIKESOFT ')

SELECT LEN(SPACE(10))

SELECT STR(123.215,1,2)

SELECT STUFF('mikechang',2,3,'sprite')

SELECT SUBSTRING('mikechang',2,3)

SELECT UNICODE('KE')

SELECT UPPER('mike')



--系统函数

SELECT APP_NAME()

SELECT COALESCE(NULL,NULL,100)

SELECT CURRENT_USER

SELECT DATALENGTH(' MIKEC ')

SELECT @@ERROR

SELECT HOST_ID()

SELECT HOST_NAME()

SELECT @@IDENTITY

SELECT NEWID()

SELECT ISDATE('20132')

 

你可能感兴趣的:(常用函数)