Q&A about the site for those interested in the study of the fundamental nature of knowledge, reality, and existence
declare @date datetime = '2016-05-01', @ndays INT = 11, @country NVARCHAR(2) BEGIN IF @date IS NULL BEGIN SET @date = GETDATE(); END IF @country IS NULL BEGIN SET @country = 'HU'; END DECLARE @count INT = 1 DECLARE @newdate datetime DECLARE @firstdayofmonth date = DATEADD(month, DATEDIFF(month, 0, @date), 0) WHILE DATEPART(weekday,@firstdayofmonth) in (7,1) BEGIN SET @firstdayofmonth = DATEADD(DAY, 1, @firstdayofmonth) END; SET @newdate = @firstdayofmonth WHILE @count < @ndays BEGIN SET @newdate = DATEADD(DAY, 1, @newdate) IF (DATEPART(WEEKDAY, @newdate) not in (1,7)) SET @count += 1; END select @newdate END