You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
6.6 KiB
90 lines
6.6 KiB
USE [Vertragsverwaltung_20160404]
|
|
GO
|
|
/****** Object: StoredProcedure [dbo].[sp_keyuser_massenupdate] Script Date: 02.12.2016 09:08:53 ******/
|
|
DROP PROCEDURE [dbo].[sp_keyuser_massenupdate]
|
|
GO
|
|
/****** Object: StoredProcedure [dbo].[sp_keyuser_massenupdate] Script Date: 02.12.2016 09:08:55 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE PROCEDURE [dbo].[sp_keyuser_massenupdate]
|
|
@fnkt int,
|
|
@kontakttypnr int,
|
|
@usernr int,
|
|
@usernrneu int=0,
|
|
@mitarbeiternr int
|
|
AS
|
|
BEGIN
|
|
-- Bestehende KeyUser auslesen
|
|
if @fnkt=0 begin
|
|
SELECT distinct dbo.Person.PersonNr, dbo.Person.Name + ' ' + dbo.Person.Vorname AS Mitarbeiter
|
|
FROM dbo.person
|
|
WHERE (dbo.person.aktiv = 1) and dbo.person.vertragspartnernr=1
|
|
ORDER BY mitarbeiter
|
|
end
|
|
|
|
if @fnkt=1 begin
|
|
SELECT DISTINCT dbo.Kontakttyp.KontakttypNr, dbo.Kontakttyp.Bezeichnung
|
|
FROM dbo.ApplikationKontakt INNER JOIN
|
|
dbo.Kontakttyp ON dbo.ApplikationKontakt.KontakttypNr = dbo.Kontakttyp.KontakttypNr
|
|
WHERE (dbo.ApplikationKontakt.Aktiv = 1) AND (dbo.Kontakttyp.Aktiv = 1)
|
|
order by bezeichnung
|
|
end
|
|
|
|
-- mögliche KeyUser auslesen
|
|
if @fnkt=2 begin
|
|
SELECT distinct dbo.Person.PersonNr, dbo.Person.Name + ' ' + dbo.Person.Vorname AS Mitarbeiter
|
|
FROM dbo.ApplikationKontakt INNER JOIN
|
|
dbo.Person ON dbo.ApplikationKontakt.PersonNr = dbo.Person.PersonNr
|
|
WHERE (dbo.ApplikationKontakt.KontakttypNr = @kontakttypnr) and dbo.applikationkontakt.aktiv=1
|
|
ORDER BY mitarbeiter
|
|
end
|
|
|
|
-- Applikationen auflisten
|
|
if @fnkt=3 begin
|
|
SELECT dbo.Applikation.Bezeichnung
|
|
FROM dbo.ApplikationKontakt INNER JOIN
|
|
dbo.Person ON dbo.ApplikationKontakt.PersonNr = dbo.Person.PersonNr INNER JOIN
|
|
dbo.Applikation ON dbo.ApplikationKontakt.Applikationnr = dbo.Applikation.ApplikationNr
|
|
WHERE (dbo.ApplikationKontakt.personnr=@usernr) and (dbo.ApplikationKontakt.kontakttypnr=@kontakttypnr)
|
|
AND (dbo.ApplikationKontakt.Aktiv = 1) AND (dbo.Applikation.Aktiv = 1)
|
|
end
|
|
|
|
if @fnkt=4 begin
|
|
declare @anr int
|
|
declare @apnr int
|
|
declare @newkey int
|
|
declare @ec int
|
|
select applikationkontaktnr, applikationnr
|
|
into #tmpa from applikationkontakt
|
|
where aktiv=1 and kontakttypnr=@kontakttypnr and personnr=@usernr
|
|
declare xc cursor for
|
|
select * from #tmpa
|
|
open xc
|
|
fetch next from xc into @anr, @apnr
|
|
while @@fetch_status=0 begin
|
|
update applikationkontakt set aktiv=0, mutiert_am=getdate(), mutierer=@mitarbeiternr where applikationkontaktnr=@anr
|
|
execute sp_get_dbkey 'ApplikationKontakt',@newkey output, @ec output
|
|
insert applikationkontakt (applikationkontaktnr, applikationnr, personnr, kontakttypnr,intern, bemerkung, aktiv,
|
|
erstellt_am, mutiert_am, mutierer, mandantnr, securitylevelnr)
|
|
values (@newkey,@apnr,@usernrneu,@kontakttypnr,0,'',1,getdate(),getdate(),@mitarbeiternr,null,0)
|
|
fetch next from xc into @anr, @apnr
|
|
end
|
|
close xc
|
|
deallocate xc
|
|
drop table #tmpa
|
|
end
|
|
|
|
END
|
|
|
|
|
|
|
|
GO
|