0

I got following table valued function (in SQL Server 2005). I got an compile error when I run --1, but --3 is ok, --2 is used to generate the parameters to be used in --3, which should be the same as in --1. But why --1 got the error?

create function test_udf_nz_2 (
    @a datetime
    ,@b datetime
)
returns @result TABLE(
    c1 datetime
    ,c2 datetime
)
as
begin
    insert into @result
    select @a, @b
    return
end


declare
    @dt_report_date DATETIME 
    ,@v_stores VARCHAR(MAX) 

select @dt_report_date = '20120831'
        ,@v_stores = '152'
--1
select * from dbo.test_udf_nz_2( DATEADD(hour,0,DATEDIFF(d,0,@dt_report_date)), DATEADD(hour,24,DATEDIFF(d,0,@dt_report_date))) AS t

--2
--select DATEADD(hour,0,DATEDIFF(d,0,@dt_report_date)), DATEADD(hour,24,DATEDIFF(d,0,@dt_report_date))

--3
select * from dbo.test_udf_nz_2( '20120831', '20120901') AS t
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
thotwielder
  • 1,563
  • 7
  • 44
  • 83

1 Answers1

0

Just found out. The compatible level of the database is set to sql server 2000 (8.0).

I didn't know function can not be used in parameters of a table valued function in 2000...

thotwielder
  • 1,563
  • 7
  • 44
  • 83