1
J'essaie d'utiliser une fonction simple dans SQL Server 2005 et il génère une erreur.Comment utiliser la table tronquée et insérer dans la table dans la fonction définie par l'utilisateur pour SQL Server 2005?
CREATE FUNCTION [dbo].[fn_data_stat_cc_update]
(
@result char
)
RETURNS char(1)
AS
BEGIN
truncate table stg_data_cancer_center;
INSERT INTO stg_data_cancer_center(
mrn, pt_city, pt_state, pt_zip, pt_pri_dx, clinic, source
SELECT rtrim(ltrim(mrn)) as mrn,
pat_city, pat_state, zipcode, exact_icd9_code_pri_dx, 'clinic' =
case
when inst_id = 1 then 'CANRAD'
when inst_id = 2 then 'CANHAM'
else @result--''
end, 'MOSAIQ' as Source
from stg_mosaiq_patient;
RETURN LTRIM(RTRIM(@result))
END
erreurs sont:
Procedure fn_data_stat_cc_update, Line 18
Invalid use of side-effecting or time-dependent operator in 'TRUNCATE TABLE' within a function.
Procedure fn_data_stat_cc_update, Line 25
Invalid use of side-effecting or time-dependent operator in 'INSERT' within a function.
Merci, Martin. Je vais créer un proc de stockage. – pots06