Hi!
It seemed to be an easy thing in T-SQL to do, but I can't solve it:
There is a table tblEventAnmeldungen containing employee number (MaID)and Status ('OK', 'NO', 'XX') of registrations of Events (EvID).
I would like to count the number of registrations (not Status 'NO'), the number of Cancelations (Status 'XX') and then calculate a reliability-rate per employee (MaID).
I can count both columns'Anmeldungen' and 'AnmeldungenXX', but I cannot divide them!!
By the way, both columns can have a 0 result.
I tried (only with one MaID):
The result set should be for example:
Anmeldungen AnmeldungenXX Reliability
6.................... 2................. 0.33
or when AnmeldungenXX=0
6................... 0.................. 1 (meaning 100%)
or when Anmeldungen=0 and of course AnmeldungenXX should be 0
0................... 0.................. 0
(the dots stand for blanks!)
Please help me in defining my stored procedure.
Thanks a lot
Michael
It seemed to be an easy thing in T-SQL to do, but I can't solve it:
There is a table tblEventAnmeldungen containing employee number (MaID)and Status ('OK', 'NO', 'XX') of registrations of Events (EvID).
I would like to count the number of registrations (not Status 'NO'), the number of Cancelations (Status 'XX') and then calculate a reliability-rate per employee (MaID).
I can count both columns'Anmeldungen' and 'AnmeldungenXX', but I cannot divide them!!
By the way, both columns can have a 0 result.
I tried (only with one MaID):
Code:
begin
declare
@Anmeldungen int,
@AnmeldungenXX int,
@Reliability decimal(4,4);
set @Anmeldungen=(SELECT count(*) FROM tblEventAnmeldungen WHERE Status<>'NO' and tblEventAnmeldungen.MaID = 2)
set @AnmeldungenXX=(SELECT count(*) FROM tblEventAnmeldungen WHERE Status='XX' and tblEventAnmeldungen.MaID = 2)
set @Reliability=@AnmeldungenXX/@Anmeldungen
--isnull((SELECT count(*) FROM tblEventAnmeldungen WHERE Status = 'XX' and tblPersonal.MaID = tblEventAnmeldungen.MaID)-NULLIF((SELECT count(*) FROM tblEventAnmeldungen WHERE Status <> 'NO' and tblPersonal.MaID = tblEventAnmeldungen.MaID),0),0) as Reliability,
select @Anmeldungen as Anmeldungen, @AnmeldungenXX as AnmeldungenXX, @AnmeldungenXX/nullif(@Anmeldungen,0) as Reliability, @Reliability
end
The result set should be for example:
Anmeldungen AnmeldungenXX Reliability
6.................... 2................. 0.33
or when AnmeldungenXX=0
6................... 0.................. 1 (meaning 100%)
or when Anmeldungen=0 and of course AnmeldungenXX should be 0
0................... 0.................. 0
(the dots stand for blanks!)
Please help me in defining my stored procedure.
Thanks a lot
Michael