You are on page 1of 1

String Functions Date Functions Create a Stored Procedure

Exact Numerics DATEADD (datepart, number, date) CREATE PROCEDURE name


bit decimal DATEDIFF (datepart, start, end) @variable AS datatype = value
tinyint money DATENAME (datepart, date) AS
smallint numeric DATEPART (datepart, date) -- Comments
bigint DAY (date) SELECT * FROM table
Approximate Numerics GETDATE() GO
float real GETUTCDATE()
Date and Time MONTH (date) Create a Trigger
smalldatetime timestamp YEAR (date)
datetime CREATE TRIGGER name
Strings Dateparts ON
char text table
varchar Year yy, yyyy FOR
Unicode Strings Quarter qq, q DELETE, INSERT, UPDATE
nchar ntext Month mm, m AS
nvarchar Day of Year dy, y -- Comments
Binary Strings Day dd, d SELECT * FROM table
binary image Week wk, ww GO
varbinary Hour hh
Miscellaneous Minute mi, n Create a View
cursor table Second ss, s
sql_variant xml Millisecond ms CREATE VIEW name
AS
-- Comments
Type Conversion Mathematical Functions
SELECT * FROM table

CAST (expression AS datatype) ABS LOG10 GO

CONVERT (datatype, expression) ACOS PI


ASIN POWER Create an Index

Ranking Functions ATAN RADIANS


ATN2 RAND CREATE UNIQUE INDEX name
CEILING ROUND ON
RANK NTILE
COS SIGN table (columns)
DENSE_RANK ROW_NUMBER
COT SIN
DEGREES SQUARE Create a Function
Grouping (Aggregate) Functions
EXP SQRT
CREATE FUNCTION name
AVG MAX FLOOR TAN
(@variable datatype(length))
BINARY_CHECKSUM MIN LOG
RETURNS
CHECKSUM SUM
datatype(length)
CHECKSUM_AVG STDEV String Functions AS
COUNT STDEVP
BEGIN
COUNT_BIG VAR ASCII REPLICATE
DECLARE @return datatype(length)
GROUPING VARP CHAR REVERSE
SELECT @return = CASE @variable
CHARINDEX RIGHT
WHEN 'a' THEN 'return a'
Table Functions DIFFERENCE RTRIM
WHEN 'b' THEN 'return b'
LEFT SOUNDEX
ELSE 'return c'
ALTER DROP LEN SPACE
RETURN @return
CREATE TRUNCATE LOWER STR
END
LTRIM STUFF
NCHAR SUBSTRING
Available free from PATINDEX UNICODE
AddedBytes.com REPLACE UPPER
QUOTENAME