server| function
CREATE VIEW V_getdate
As
Select GETDATE () [Output]
Go
---------------------------------------------------------------
Create function F_getdate ()
returns datetime
As
Begin
DECLARE @n datetime
Select @n = output from v_getdate
Return (@n)
End
Go
---------------------------------------------------------------
Call: Select Dbo.f_getdate ()
======================================================================
-----The following is the parsing--------
Should not be allowed inside function
The function can be either determined or indeterminate. If the result is always the same when the function is invoked with a specific set of input values, the functions are determined. If you use the same set of specific input values each time the function is invoked, and the results returned are always different, the functions are indeterminate.
An indeterminate function can have a side effect. Side effects are changing some of the global state of the database, such as updating a database table or some external resources, such as a file or network (for example, modifying a file or sending an e-mail message).
Built-in indeterminate functions in the body of a user-defined function are not allowed;
@ @CONNECTIONS @ @TOTAL_ERRORS
@ @CPU_BUSY @ @TOTAL_READ
@ @IDLE @ @TOTAL_WRITE
@ @IO_BUSY GETDATE
@ @MAX_CONNECTIONS getUTCDate
@ @PACK_RECEIVED NEWID
@ @PACK_SENT RAND
@ @PACKET_ERRORS TEXTPTR
@ @TIMETICKS
Although indeterminate functions are not allowed in the body of a user-defined function, these user-defined functions can still have side effects when calling an extended stored procedure.
Because extended stored procedures can have side effects on the database, the function that invokes the extended stored procedure is indeterminate. When a user-defined function call extends stored procedures that have side effects on the database, do not expect the result set to remain consistent or perform functions.