Untitled

mail@pastecode.io avatar
unknown
sql
a year ago
1.0 kB
7
Indexable
Never
--declare @eventparam2 varchar(100) = '[{"Date":"2022-10-19","Delta":5,"Comment":null}]', @eventParam3 int = 28628, @contextid int = 1193958

DECLARE @UserOrgStrUnitId table (UserID INT)

INSERT @UserOrgStrUnitId
select distinct uos.UserID
from UserOrgStructureUnit uos with(nolock)
	JOIN OrgStructureUnit os
		ON uos.OrgStructureUnitId = os.id	
			and os.id not in (2965, 1977, 2264)
	JOIN Users u  with(nolock)
		ON uos.UserID = u.UserID 
where ParentId in (3004, 2257, 2256)		
		and IsFired_2 = 0
 
--select * from @UserOrgStrUnitId

declare @delta int
select @delta = JSON_VALUE(@eventparam2, '$[0].Delta')

if @delta < 0
begin
select 0 
return
end

declare @date nvarchar(max) 
select @date = JSON_VALUE(@eventparam2, '$[0].Date')


IF 
	@eventparam3 in (select userid 
					 from @UserOrgStrUnitId)
				and dbo.tc_DiffWorkingDays(convert(datetime, @date, 121),  getdate()) >= 5 
	select 1
	else 
    select 0

from tasksinsubcat865denormalized 
where taskid = @contextid