Use create function to create scalar functions that include:
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 (only valid in the scope of the function).
Adaptive Server does not allow fetch statements in a scalar function that return data to the client. You cannot include :
select or fetch statements that returns data to the client.
insert, update, or delete statements.
Utility commands, such as dbcc, dump and load commands.
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.