Not wanting to lleave the topic closed with incorrect info.. here are the Corrections.. :
Alter FUNCTION [dbo].[FctDateTime_FirstDayOfWeek2]
(
-- Add the parameters for the function here
@Date date
)
RETURNS date
with schemabinding
AS
BEGIN
declare @firstDate date
declare @Daysdiff int = dateDiff(dd,(datefromparts('1900','01','01')),@Date)%7 --- ***Correct line. Cast is not determenistic
select @firstDate = DATEADD(dd, @Daysdiff*-1, @Date)
RETURN @firstDate
END
OR
Alter FUNCTION [dbo].[FctDateTime_FirstDayOfWeek2]
(
-- Add the parameters for the function here
@Date date
)
RETURNS date
with schemabinding
AS
BEGIN
declare @firstDate date
declare @Daysdiff int = dateDiff(dd,(CONVERT(datetime, '1900-01-01', 101)),@Date)%7 ---*** Changed line. Convert is determenistic.
select @firstDate = DATEADD(dd, @Daysdiff*-1, @Date)
RETURN @firstDate
END