-2
votes

Syntaxe incorrecte près ','. Et syntaxe incorrecte près ')'

J'ai un problème avec des crochets et je ne sais pas où l'erreur est. XXX PRE>

Message d'erreur P>

Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ','.
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ')'.


0 commentaires

6 Réponses :


0
votes

Vous avez utilisé des parenthèses inappropriées ainsi que des virgules. De plus, j'ai ajouté commencer code> et fin code> pour la définition de la section. Voici votre code de travail

select @theDay
select @theMonth


0 commentaires

1
votes
DECLARE @theDate varchar(60)

DECLARE @theDay varchar(6)

DECLARE @theMonth varchar(6)

SET @theDate = GETDATE()

 IF(CAST(DAY(@theDate)as int) > 9 )

  SET @theDay = CAST(DAY(@theDate)as Varchar(6))

 else

  SET @theDay = '0' +( CAST(DAY(@theDate)as Varchar(6)));

IF(CAST(DAY(@theDate)as int) > 9 )

 SET @theMonth = CAST(MONTH(@theDate)as Varchar(6))

else

 SET @theMonth = '0' + (CAST(MONTH(@theDate)as Varchar(6)));
Please use proper if else syntax as above.

0 commentaires

0
votes

Pourquoi pas simplement le faire comme ceci:

select DAY(GETDATE())
select MONTH(GETDATE())


0 commentaires

0
votes

Peut-être que vous devriez essayer ce code.

DECLARE @theDate varchar(60)
DECLARE @theDay varchar(6)
DECLARE @theMonth varchar(6)

SET @theDate = GETDATE()

IF
  CAST(DAY(@theDate)as int) > 9
THEN
  SET @theDay = CAST(DAY(@theDate)as Varchar(6))
ELSE
  SET @theDay = '0' + CAST(DAY(@theDate)as Varchar(6))
END

IF
  CAST(DAY(@theDate)as int) > 9
THEN
  SET @theMonth = CAST(MONTH(@theDate)as Varchar(6))
ELSE
  SET @theMonth = '0' + CAST(MONTH(@theDate)as Varchar(6))
END


0 commentaires

0
votes

Lorsque vous utilisez si dans la requête SQL, il est préférable d'utiliser le début et la fin après la boucle IF. Vous pouvez essayer cela.

si (moulage (jour (@ iDeDate) comme int)> 9) Commencer SET @THEDAY = CAST (jour (@ iDeDate) comme Varchar (6)); SET @THEDAY = '0' + CAST (JOUR (@ IDÉDATE) AS VARCHAR (6)); Finir Si (moulage (jour (@thedate) comme int)> 9) COMMENCER Définir @Theemonth = moulage (mois (@thedate) comme varchar (6)); Définir @Theemonth = '0' + Cast (mois (@thedate) comme Varchar (6)); FINIR Fin


0 commentaires

0
votes

Comme d'autres l'ont dit, ce n'est pas la syntaxe de la déclaration conditionnelle. Il devrait être:

DECLARE @theDate varchar(60)
DECLARE @theDay varchar(6)
DECLARE @theMonth varchar(6)

SET @theDate = GETDATE()
set @theDay = Format(DAY(@theDate), '00')
set @theMonth = Format(MONTH(@theDate), '00')


0 commentaires