String Functions Create a Stored Procedure CREATE ...

String Functions

Exact Numerics

Date Functions

Create a Stored Procedure

DATEADD (datepart, number, date)

CREATE PROCEDURE name

bit

decimal

DATEDIFF (datepart, start, end)

tinyint

money

DATENAME (datepart, date)

smallint

numeric

DATEPART (datepart, date)

bigint

@variable AS datatype = value

AS

-- Comments

SELECT * FROM table

DAY (date)

Approximate Numerics

real

float

GETDATE()

Date and Time

MONTH (date)

smalldatetime

timestamp

GO

GETUTCDATE()

Create a Trigger

YEAR (date)

datetime

CREATE TRIGGER name

Strings

ON

Dateparts

text

char

varchar

Unicode Strings

ntext

nchar

nvarchar

Binary Strings

image

binary

varbinary

Miscellaneous

table

Year

yy, yyyy

Quarter

qq, q

Month

mm, m

Day of Year

dy, y

Day

dd, d

Week

wk, ww

Hour

hh

Minute

mi, n

cursor

table

Second

ss, s

sql_variant

xml

Millisecond

ms

FOR

DELETE, INSERT, UPDATE

AS

-- Comments

SELECT * FROM table

GO

Create a View

CREATE VIEW name

AS

Type Conversion

CAST (expression AS datatype)

ABS

LOG10

CONVERT (datatype, expression)

ACOS

PI

ASIN

POWER

ATAN

RADIANS

ATN2

RAND

CEILING

ROUND

COS

SIGN

COT

SIN

DEGREES

SQUARE

Ranking Functions

RANK

NTILE

DENSE_RANK

ROW_NUMBER

Grouping (Aggregate) Functions

MAX

AVG

-- Comments

Mathematical Functions

BINARY_CHECKSUM MIN

SUM

CHECKSUM

EXP

SQRT

FLOOR

TAN

LOG

CREATE UNIQUE INDEX name

ON

table (columns)

Create a Function

CREATE FUNCTION name

(@variable datatype(length))

datatype(length)

STDEV

COUNT

STDEVP

COUNT_BIG

VAR

ASCII

REPLICATE

GROUPING

VARP

CHAR

REVERSE

CHARINDEX

RIGHT

DIFFERENCE

RTRIM

LEFT

SOUNDEX

String Functions

AS

ALTER

DROP

LEN

SPACE

CREATE

TRUNCATE

LOWER

STR

LTRIM

STUFF

NCHAR

SUBSTRING

Available free from

PATINDEX

UNICODE



REPLACE

UPPER

QUOTENAME

Create an Index

RETURNS

CHECKSUM_AVG

Table Functions

SELECT * FROM table

GO

BEGIN

DECLARE @return datatype(length)

SELECT @return = CASE @variable

WHEN 'a' THEN 'return a'

WHEN 'b' THEN 'return b'

ELSE 'return c'

RETURN @return

END

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download