1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| BEGIN TRANSACTION CHECK_AND_INSERT_PROJECT
DECLARE @id_project int
IF EXISTS (SELECT PROJECT.name
FROM PROJECT
JOIN INSERTED
ON PROJECT.name = INSERTED.project_name
JOIN CUSTOMER
ON PROJECT.id_customer != @id_customer
WHERE (NOT (INSERTED.project_name LIKE N'TAM_%')) )
BEGIN
PRINT 'Wrong customer_name for this project. Please check...'
DECLARE @bin_check bit
SET @bin_check = 1
--ROLLBACK TRANSACTION CHECK_AND_INSERT_PROJECT
END
ELSE
BEGIN
IF EXISTS (SELECT PROJECT.name
FROM PROJECT
JOIN INSERTED
ON PROJECT.name = INSERTED.project_name
JOIN CUSTOMER
ON PROJECT.id_customer = @id_customer)
BEGIN
SET @id_project = (SELECT PROJECT.id_project
FROM PROJECT
JOIN INSERTED
ON PROJECT.name = INSERTED.project_name
JOIN CUSTOMER
ON PROJECT.id_customer = CUSTOMER.id_customer)
PRINT 'Le nom de projet existe pour numéro de client ci-dessus :'
PRINT (@id_project)
END
ELSE
BEGIN
DECLARE @project_name nvarchar(255)
SET @project_name = (SELECT project_name FROM INSERTED)
INSERT INTO PROJECT (PROJECT.name, PROJECT.id_customer)
VALUES (@project_name, @id_customer)
SET @id_project = SCOPE_IDENTITY()
PRINT 'Le projet n''existe pas. Insertion d''nouveau projet avec le numéro de client '
PRINT (@id_project)
PRINT 'avec le numéro de client'
PRINT (@id_customer)
END
END
IF @bin_check = 1
ROLLBACK TRANSACTION CHECK_AND_INSERT_PROJECT
ELSE
COMMIT TRANSACTION CHECK_AND_INSERT_PROJECT |
Partager