Bonjour,
Je suis débutante avec sql server et je voudrais créer la fonction suivante :
Mais le message d'erreur me s'affiche:
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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 CREATE FUNCTION [dbo].[advcdSearch] ( @adress nvarchar(4000), @type nvarchar(4000), @desc nvarchar(4000) ) RETURNS Table AS RETURN ( if (@adress is not null and @type is not null and @desc is not null ) begin SELECT dbo.Places.idPlace from dbo.Places,dbo.Description where(CONTAINS(dbo.Description.exactAdress,@adress) and CONTAINS(dbo.Description.specificDesc,@desc) and CONTAINS(dbo.Description.type,@type)) and dbo.Places.idDesc=dbo.Description.idDesc end else if(@adress is not null and @type is not null and @desc is null) begin SELECT dbo.Places.idPlace from dbo.Places,dbo.Description where(CONTAINS(dbo.Description.exactAdress,@adress) and CONTAINS(dbo.Description.type,@type)) and dbo.Places.idDesc=dbo.Description.idDesc end else if(@adress is null and @type is not null and @desc is not null) begin SELECT dbo.Places.idPlace from dbo.Places,dbo.Description where(CONTAINS(dbo.Description.specificDesc,@desc)and CONTAINS(dbo.Description.type,@type)) and dbo.Places.idDesc=dbo.Description.idDesc end else begin Print 'aucun résultat' end )
Malgrès que ce même bolc if..else if..else marche bien dans une procédure .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Msg 156, Level 15, State 1, Procedure advcdSearch, Line 9 Incorrect syntax near the keyword 'if'. Msg 102, Level 15, State 1, Procedure advcdSearch, Line 37 Incorrect syntax near ')'.
je ne comprends pas d'où vient le problème
Merci de m'aider
Partager