Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create trigger meow on [M_KB].[WUD\Karachev1].[Книги]
- instead of insert
- as
- begin
- declare cur cursor for (select * from inserted);
- open cur;
- declare @idRed int;
- declare @date date;
- declare @idCont int;
- declare @dateCont date;
- declare @man int;
- declare @name varchar(50);
- declare @cost money;
- declare @some money;
- declare @autcost money;
- declare @tir int;
- declare @osttir int;
- declare @temp int;
- declare @count int;
- fetch next from cur into @idCont, @dateCont, @man, @name, @cost, @some, @autcost,@date, @tir, @idRed,@osttir ;
- while @@FETCH_STATUS = 0
- begin
- if (DATEDIFF(day,GetDate(),@date)>0)
- begin
- select @count = meow from(
- select [Ответственный редактор], Count(*) as meow from [M_KB].[WUD\Karachev1].[Книги]
- where DATEDIFF(day,GetDate(),[Дата выхода])>0
- group by [Ответственный редактор]) as a
- where [Ответственный редактор]=@idRed;
- if(@count = 5)
- begin
- if(exists( select [Ответственный редактор], Count(*) as meow from [M_KB].[WUD\Karachev1].[Книги]
- where DATEDIFF(day,GetDate(),[Дата выхода])>0
- group by [Ответственный редактор]
- Having Count(*) >5))
- begin
- select top 1 @temp = [Ответственный редактор] from(
- select [Ответственный редактор], Count(*) as meow from [M_KB].[WUD\Karachev1].[Книги]
- where DATEDIFF(day,GetDate(),[Дата выхода])>0
- group by [Ответственный редактор]
- Having Count(*) >5) as b
- insert into [M_KB].[WUD\Karachev1].[Книги] values(@idCont, @dateCont, @man, @name, @cost, @some, @autcost,@date, @tir, @temp,@osttir) ;
- end
- end
- else
- begin
- insert into [M_KB].[WUD\Karachev1].[Книги] values(@idCont, @dateCont, @man, @name, @cost, @some, @autcost,@date, @tir, @idRed,@osttir) ;
- end
- end
- else
- begin
- insert into [M_KB].[WUD\Karachev1].[Книги] values(@idCont, @dateCont, @man, @name, @cost, @some, @autcost,@date, @tir, @idRed,@osttir) ;
- end
- fetch next from cur into @idCont, @dateCont, @man, @name, @cost, @some, @autcost,@date, @tir, @idRed,@osttir ;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement