Here is my SQL script and I want the code to check if ExitPermissionNo Column has no CCS_Reference then Update the column with new CCS_reference number and If ExitPermissionNo already has a CCS_Reference number then give an error message stating "Already in Database" and If ExitPermissionNo was not found, give an error message " The ExitPermissionNo Not Found". I wrote it like this and it does not work with all 3 conditions. Any help would be appreciated.
if ((SELECT ExitPermissionNo FROM ExitPermission WHERE (ExitPermissionNo = '333333333'))!=1)
begin
if (SELECT 'CCS_Reference' FROM ExitPermission WHERE 'CCS_Reference' IS NULL )=1
begin
PRINT 'Already In DataBase'
end
else
begin
UPDATE ExitPermission
SET CCS_Reference = 'joon'
WHERE ExitPermissionNo = '333333333';
PRINT 'The ReferenceCCS Update Successfully!'
end
end
else
begin
PRINT 'The ExitPermission Not Found!'
RAISERROR('The ExitPermission Not Found!',18,1)
end
Aucun commentaire:
Enregistrer un commentaire