:::: MENU ::::

Invalid use of side-effecting or time-dependent operator in ‘PRINT’ within a function.

  • Sep 15 / 2008
  • 1
dbDigger, User Defined Functions UDF

Invalid use of side-effecting or time-dependent operator in ‘PRINT’ within a function.

If you get error message
“Invalid use of side-effecting or time-dependent operator in ‘PRINT’ within a function.”
in your function (UDF), then it means you are using print statement in UDF.
Using print in UDF is not allowed. As alternate try to use select statement compatible with your return data type.
Another reason may to create a non deterministic UDF. In TSQL, UDF function must be deterministic. It must always return the same value when using the same parameter(s). For example if you use NEWID() function in UDF then you will get the mentioned error.

For example, consider the following script to create UDF in which we used RAND(). Executing it will generate the mentioned error.

 
CREATE udf_TEST()  
 RETURNS FLOAT  
 AS  
 BEGIN  
 RETURN RAND()  
 END  
 GO  

Also make sure that you are not using transnational processing on the database in a UDF. Also you can´t execute store procedures in a UDF or you may get above error.

  • please give a sample of using select statement,
    I think select cannot be used in function which returns only scalar

Consult us to explore the Databases. Contact us