Hi, I need help with a udf function in MSSQL, please. We have a program that we put a due date in a particular field and we have child events that generate from that date and are uploaded to Outlook through Exchange. What we are trying to do is make those child events never pop on a weekend. If the date falls on a Saturday it needs to push back to Thursday and the Sunday date would push back to Friday. We had someone write a script for us but we can't make it work. I am pasting it in here in hopes that someone may be able to help.
/****** Object: UserDefinedFunction [dbo].[udf_WKDELIM] Script Date: 01/21/2013 12:15:46 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE FUNCTION [dbo].[udf_WKDELIM] (@dtDate DATETIME, @strPrev VARCHAR(10))
DECLARE @intDay INT
DECLARE @rtResult DATETIME
SET @intDay = DATEPART(weekday,@dtDate)
--To find Previous working day
Set @strPrev = 'Previous'
IF @intDay = 1
SET @rtResult = DATEADD(d,-2,@dtDate)
IF @intDay = 2
SET @rtResult = DATEADD(d,-3,@dtDate)
--Default case returns date passed to function
SET @rtResult = @dtDate