Use the create function command to create and save your own scalar Transact-SQL functions. You can 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 (valid only in the scope of the function)
You cannot include :
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.
You can also create Transact-SQL functions that return a value specified by a Java method. Use the create function (SQLJ) command to add a Transact-SQL wrapper to a Java method. See Java in the Adaptive Server Database and the Reference Manual: Commands.