Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replacing VFP Function with SQL Server
Message
From
09/10/2014 13:07:40
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01609065
Message ID:
01609067
Views:
60
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform