What's wrong with this?
DECLARE @error int
If (SELECT ID_Projet FROM tblProjet WHERE No_Projet=@no_Projet)> 0
SET @error=1
END IF
The END IF is incorrect.
Do it like this:
DECLARE @error int
If (SELECT ID_Projet FROM tblProjet WHERE No_Projet=@no_Projet)> 0
SET @error=1
or this:
DECLARE @error int
If (SELECT ID_Projet FROM tblProjet WHERE No_Projet=@no_Projet)> 0
Begin
SET @error=1
End
Check HERE for documentation.
If you're trying to see the number of rows with that restriction you should do it like this:
DECLARE @error int
If (SELECT count(ID_Projet) FROM tblProjet WHERE No_Projet=@no_Projet)> 0
Begin
SET @error=1
End
END IF is not T-SQL syntax for conditional statements.
DECLARE @error int
IF (SELECT COUNT(ID_Projet) FROM tblProjet WHERE No_Projet=@no_Projet)> 0
BEGIN
SET @error=1
END
EDIT:
Since this is only checking for at least one row you should use the EXISTS functionality rather than COUNT. This is much more efficient, if ID_Project is nullable you will need to add a further WHERE clause to the EXISTS Query to add "AND ID_Projet IS NOT NULL" since COUNT(NULL) = 0
DECLARE @error int
IF EXISTS(SELECT ID_Projet FROM tblProjet WHERE No_Projet=@no_Projet)
BEGIN
SET @error=1
END
>0matching rows or test whether theID_Projetvalue is>0?