Bonjour
J'ai beau relire les exemples de syntaxe d'un Create Function je ne comprends pas pourquoi l'intruction suivante dont j'ai trouvé l'exemple sur Google me donne une erreur a chaque ligne ?
Ou est l'erreur ?
Merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 CREATE FUNCTION fct_isoyear @MyDate AS dateTime RETURNS INT AS DECLARE @ISOyear INT = DATEPART(YEAR, @MyDate); -- Special cases: Jan 1-3 may belong to the previous year IF (DATEPART(MONTH, @MyDate) = 1 AND DATEPART(ISO_WEEK, @MyDate) > 50) SET @ISOyear = @ISOyear - 1; -- Special case: Dec 29-31 may belong to the next year IF (DATEPART(MONTH, @MyDate) = 12 AND DATEPART(ISO_WEEK, @MyDate) < 45) SET @ISOyear = @ISOyear + 1 RETURN @ISOYear;Msg 102, Level 15, State 1, Procedure isoyear, Line 1
Incorrect syntax near '@MyDate'.
Msg 137, Level 15, State 2, Procedure isoyear, Line 4
Must declare the scalar variable "@MyDate".
Msg 137, Level 15, State 2, Procedure isoyear, Line 7
Must declare the scalar variable "@MyDate".
Msg 137, Level 15, State 2, Procedure isoyear, Line 8
Must declare the scalar variable "@ISOyear".
Msg 137, Level 15, State 2, Procedure isoyear, Line 11
Must declare the scalar variable "@MyDate".
Msg 137, Level 15, State 2, Procedure isoyear, Line 12
Must declare the scalar variable "@ISOyear".
Msg 137, Level 15, State 2, Procedure isoyear, Line 14
Must declare the scalar variable "@ISOYear".
Partager