Monday, May 16, 2011

Can we Use PRINT statement inside a SQL server (T-SQL) function


We cannot use a PRINT statement in a function. It would give the following error when trying to compile it.

Example:

CREATE FUNCTION Hello()
RETURNS varchar(100)
as
BEGIN
      PRINT 'MY HELLO';
      RETURN ('Hello');
END
GO
Msg 443, Level 16, State 14, Procedure Hello, Line 6
Invalid use of side-effecting or time-dependent operator in 'PRINT' within a function.

No comments:

Post a Comment