Witam, mam problem ponieważ nie moge stworzyć funkcji która posiada w swoim ciele transakcje. Środowisko Microsoft SQL 2008
CREATE FUNCTION f_zapomoga (@album INT, @semestr INT, @kwota FLOAT)
RETURNS INT
AS
BEGIN
DECLARE @tok_studiow INT;
DECLARE @ilosc_niepoz INT;
DECLARE @akt_status_stud_id INT;
DECLARE @sukces INT;
SET @sukces = 0
EXEC @tok_studiow = zwroc_tok_studiow @album, @semestr;
SELECT @akt_status_stud_id = status_stud_id FROM etap WHERE etap_id = @tok_studiow;
BEGIN TRY
BEGIN TRANSACTION
UPDATE etap_id SET status_stud_id = 1 WHERE etap_id = @tok_studiow;
INSERT INTO stypendium (etap_id, kwota, komunikat, rodzaj_styp_id, status_styp_id) VALUES (@tok_studiow, @kwota, 'Przyznano zapomogę', 5, 1);
UPDATE etap_id SET status_stud_id = @akt_status_stud_id WHERE etap_id = @tok_studiow;
SET @sukces = @sukces+1;
COMMIT
END TRY
BEGIN CATCH
--sprawdza czy wystapil blad
IF @@TRANCOUNT > 0
ROLLBACK
DECLARE @ErrorMessage nvarchar(4000), @ErrorSeverity int;
SELECT @ErrorMessage = ERROR_MESSAGE(),@ErrorSeverity = ERROR_SEVERITY();
RAISERROR(@ErrorMessage, @ErrorSeverity, 1);
END CATCH
RETURN @sukces;
END;
i komunikat:
Msg 443, Level 16, State 14, Procedure f_zapomoga, Line 15
Invalid use of a side-effecting operator 'BEGIN TRY' within a function.
Msg 443, Level 16, State 15, Procedure f_zapomoga, Line 16
Invalid use of a side-effecting operator 'BEGIN TRANSACTION' within a function.
Msg 443, Level 16, State 15, Procedure f_zapomoga, Line 18
Invalid use of a side-effecting operator 'INSERT' within a function.
Msg 443, Level 16, State 15, Procedure f_zapomoga, Line 21
Invalid use of a side-effecting operator 'COMMIT TRANSACTION' within a function.
Msg 443, Level 16, State 14, Procedure f_zapomoga, Line 22
Invalid use of a side-effecting operator 'END TRY' within a function.
Msg 443, Level 16, State 14, Procedure f_zapomoga, Line 23
Invalid use of a side-effecting operator 'BEGIN CATCH' within a function.
Msg 443, Level 16, State 15, Procedure f_zapomoga, Line 26
Invalid use of a side-effecting operator 'ROLLBACK TRANSACTION' within a function.
Msg 443, Level 16, State 14, Procedure f_zapomoga, Line 29
Invalid use of a side-effecting operator 'RAISERROR' within a function.
Msg 443, Level 16, State 14, Procedure f_zapomoga, Line 30
Invalid use of a side-effecting operator 'END CATCH' within a function.