>Hi, I'm not quite sure I follow the original problem, but if you want the SQL equivalent....I've kept the parameter order the way you wanted, though personally I think you want to reverse them.
>
>Here is SQL equivalent.. Not sure if this will solve everything you're encountering, but here goes.
>
>
>CREATE FUNCTION dbo.DaysToComplete
>(@CloseDate Date, @OpenDate Date)
>RETURNS INT
>AS
> BEGIN
> DECLARE @DayDiff int = DATEDIFF(D, @OpenDate, @CloseDate)
> if @DayDiff < 0
> set @DayDiff = 0
> return @DayDiff
> end
>
>
>Here are 2 tests...
>
>
>select dbo.DaysToComplete( '5/1/2014', '5/15/2014') returns zero
>select dbo.DaysToComplete( '5/15/2014', '5/1/2014') returns 14
>
Kevin, Thank you very much for the code. Do I understand that once I create this function, then the following SQL Select should work:
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?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham