I'm trying to create a userdefined scalar function where i subtract the number of days (eliminating weekends) from one starting point [starting] to [arrival], but these two columns are in different tables. In a long-winded query , the order# will correlate with each of these inside the respective tables:

create function [dbo].fn_daysapart

returns int

as

begin

return(select (DATEDIFF(dd,convert(datetime,t1.starting,121),t2.arrival) -

(2 * DATEDIFF(wk,convert(datetime,t1.starting,121),t2.arrival)) from tableorders t1,tabledetails t2 )

end

...but i get "incorrect syntax near the FROM keyword" error , even tho i believe i hav my parenthesis correctly positioned (and am not getting intellisense red squigglies on any of these)

??

Thanks