Hi,
Just want to validate that, contrary to 2000, 2005 will tolerate the use of SELECT statements within functions.
Thanks
Hi,
Just want to validate that, contrary to 2000, 2005 will tolerate the use of SELECT statements within functions.
Thanks
That's not true. BOTH SQL 2000 and 2005 will allow the proper use of SELECT statements inside the function.
However, neither will allow a SELECT statement to be used to return data to the client outside of the defined function data return (either scalar or TVF.)
Thanks
Are you aware of any difference between the 2 versions (regarding functions)
Yes, there is a lot of new functionality that can be employed in User Defined Functions. New T-SQL keywords, xml datatypes, xquery, clr functions, etc. The list of new capabilities is very long.
Can you be more specific about your needs
Arnie Rowland wrote:
Yes, there is a lot of new functionality that can be employed in User Defined Functions. New T-SQL keywords, xml datatypes, xquery, clr functions, etc. The list of new capabilities is very long.
Can you be more specific about your needs
Sorry...
I meant besides new functionnalities in SQL Server 2005 (which cannot be used in 2000).
We found the problem...
We were trying to implement a function to bypass the real datetime. So instead of using getdate(), we would use fn_getdate().
fn_getdate() returns either a date from a table or getdate() if no value is found.
In SQL 2000 you cannot use getdate() in a function. That was the source of the error.
Thanks
IF OBJECT_ID (N'dbo.fn_getdate', N'FN') IS NOT NULL
DROP FUNCTION dbo.fn_getdate;
GO
CREATE FUNCTION dbo.fn_getdate ()
RETURNS datetime
AS
BEGIN
DECLARE @newdate datetime
SELECT @newdate= CASE WHEN dt.date IS NULL THEN GETDATE() ELSE dt.date END FROM TestTable dt
RETURN(@newdate)
END;
GO
SELECT dbo.fn_getdate()
IF OBJECT_ID (N'dbo.fn_getdate', N'FN') IS NOT NULL
DROP FUNCTION dbo.fn_getdate
GO
CREATE FUNCTION dbo.fn_getdate(@curdate AS DATETIME)
RETURNS datetime
AS
BEGIN
DECLARE @newdate datetime
SELECT @newdate=NULL --- Insert code here for table
IF @newdate IS NULL
SET @newdate = @curdate
RETURN(@newdate)
END
GO
SELECT dbo.fn_getdate(GETDATE())
Hi Tom,
Nice workaround... Thanks
I've been through many articles about differences between 8.0 and 9.0 but none mention this one. Do you know the reason behind and are you aware of similar differences
Thanks again
Tom Phillips wrote:
I generally stay away from functions because of performance issues. UDF are very costly in execution time. If you can do what you want another way, without a UDF, I would.
What do you mean by "very costly"
I ran benchmarks and in my case the results show UDFs are slower by about 10%.