>select * from MyTable where DAYSTOCOMPLETE( DATE_CLOS, DATE_OPEN)>23)
>
>Where DATE_CLOS and DATE_OPEN are two column names of the table. Should this code work or I have to change the syntax?
First, I'd recommend always referencing the schema..... WHERE dbo.DaysToComplete....
Second, performance will be better if you do it inline....
WHERE DATEDIFF(D, OpenDate, CloseDate) > 23
I'm not a fan of scalar functions in SQL, because you can get really bad performance sometimes. Unless the benefit of a function is much higher than performance, it's better to use it inline.