Bonjour,

Je souhaiterais créer une procédure stockée qui effectue une recherche en fonction de deux paramètres. Le paramètre 1 n'est jamais NULL mais le problème c'est que si mon paramètre 2 est NULL, le résultat de ma requête ne donnera rien c'est pourquoi j'ai voulu écrire ceci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ALTER PROCEDURE [dbo].[lstsos] 
	-- Add the parameters for the stored procedure here
	@Param1 nvarchar(255),
	@Param2 nvarchar(255)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
 
    -- Insert statements for procedure here
 
IF (@Param2 is NULL) THEN
select designation + ' -- ' + cast(month(date_livraison) as nvarchar) + ' -- ' + cast(montant_commande as nvarchar) as newcol, sos_id from sos where demandeur_demande = (select demandeur_code from sos_demandeur where demandeur_name = @param1)
ELSE;
select designation + ' -- ' + cast(month(date_livraison) as nvarchar) + ' -- ' + cast(montant_commande as nvarchar) as newcol, sos_id from sos where demandeur_demande = (select demandeur_code from sos_demandeur where demandeur_name = @param1 and designation like '%' + @param2 + '%')
END IF
END
Je ne vois pas trop ce qui cloche, cependant j'obtiens les erreurs suivantes:

Msg 156, Level 15, State 1, Procedure lstsos, Line 18
Incorrect syntax near the keyword 'THEN'.
Msg 156, Level 15, State 1, Procedure lstsos, Line 20
Incorrect syntax near the keyword 'ELSE'.
Msg 156, Level 15, State 1, Procedure lstsos, Line 23
Incorrect syntax near the keyword 'END'.
Quelqu'un sait-il d'oû peut provenir le problème ?

Merci beaucoup