Of course I ve seen the other questions about this subject but it's not entirely clear.
In the Northwind db, run this query:
select * from orders where Datediff("d",[OrderDate],Getdate()) > 3100
Now I want to use it in a function, so I would create the function like this:
create FUNCTION dbo.udf_orders (@mydate datetime)
select * from orders where Datediff("d",[OrderDate],@mydate) > 3100
All fine. (Would make sense to pass the 3100 as a parameter as well but this is not relvant for the question.)
But calling the function causes a problem:
Select * from dbo.udf_orders(GetDate()) gives an error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '('.
Any ideas how to use this function?