I would like to find out what the logic behind the SQL Syntax is when including a hyphen before calling a SQL function enclosed in parentheses.
Here is the SQL:
IF (@StartDate > @EndDate)
BEGIN
SET @EndDate = @StartDate
SET @StartDate = @EndDate
END
DECLARE @nonworkingweekdays int
--now deal with public holidays
SELECT @nonworkingweekdays = count("Date") from
(
select distinct
(
CASE datepart(weekday,date)
WHEN 1 THEN null --ignore sundays
WHEN 7 THEN null --ignore saturdays
else "Date"
END
) AS "date"
from publicholidays
) nonworkingweekdays
WHERE
"Date" is not null and
"Date" between @StartDate and DATEADD(day, -1, @EndDate)
RETURN
CASE WHEN @StartDate <= @EndDate
THEN
dbo.FullWeekDays(@StartDate, @EndDate) - @nonworkingweekdays
ELSE
-(dbo.FullWeekDays(@StartDate, @EndDate) - @nonworkingweekdays)
END
The logic I am confused about is in the else statement with the return statement at the bottom of this script.
Thanks in advance :)
It's the TSQL Unary Negative Operator: