Use the create function command to create and save your own scalar Transact-SQL functions.
declare statements to define data variables and cursors that are local to the function
Assigned values to objects local to the function (for example, assigning values to scalar and variables local to a table with select or set commands)
Cursor operations that reference local cursors that are declared, opened, closed, and deallocated in the function
Control-of-flow statements
set options (valid only in the scope of the function)
select or fetch statements that return data to the client
insert, update, or delete statements
Utility commands, such as dbcc, dump and load
print statements
Statements that references rand, rand2, getdate, or newid
You can include select or fetch statements that assign values only to local variables.
See the Reference Manual: Commands.