Non-database programmer here. It happens so, that I need to create a function in T-SQL which returns workdays count between given dates. I believe that the easiest how it's done is with while loop. Problem is, that as soon as I write something like
while @date < @endDate
begin
end
the statement won't execute, claiming "incorrect syntax near the keyword 'return'" (not very helpful). Where's the problem?
P.S. Full code:
ALTER FUNCTION [dbo].[GetNormalWorkdaysCount] (
@startDate DATETIME,
@endDate DATETIME
)
RETURNS INT
AS
BEGIN
declare @Count INT,
@CurrDate DATETIME
set @CurrDate = @startDate
while (@CurrDate < @endDate)
begin
end
return @Count
END
GO