Skip to content
Advertisement

Incorrect syntax in query

Hello i have this query :

strSQL =    "SELECT DATEPART(yyyy,ArriveDate) AS God," & _

"COUNT (CASE  DATEPART(d,ArriveDate) WHEN 1 THEN DATEPART(d,ArriveDate) END)As m1 ," & _
"COUNT (CASE  DATEPART(d,ArriveDate) WHEN 2 THEN DATEPART(d,ArriveDate) END)As m2 ," & _
"COUNT (CASE  DATEPART(d,ArriveDate) WHEN 3 THEN DATEPART(d,ArriveDate) END)As m3 ," & _
"COUNT (CASE  DATEPART(d,ArriveDate) WHEN 4 THEN DATEPART(d,ArriveDate) END)As m4 " & _

 " FROM Company " & _

  " WHERE DATEPART(yyyy,ArriveDate) =" & [Forms]![Raport_lunar_anual_carnete]![ANUL] & _

  " AND DATEPART(mm,ArriveDate)= " & [Forms]![Raport_lunar_anual_carnete]![LUNA] & _

  " GROUP BY DATEPART(yyyy,ArriveDate)"

It says me that : Incorrect syntax near the keyword “AND”

Advertisement

Answer

Try this

strSQL =          " SELECT DATEPART(yyyy,ArriveDate) AS God,"    
strSQL = strSQL & "   COUNT (CASE  DATEPART(d,ArriveDate) WHEN 1 THEN DATEPART(d,ArriveDate) END)As m1 ,"
strSQL = strSQL & "   COUNT (CASE  DATEPART(d,ArriveDate) WHEN 2 THEN DATEPART(d,ArriveDate) END)As m2 ," 
strSQL = strSQL & "   COUNT (CASE  DATEPART(d,ArriveDate) WHEN 3 THEN DATEPART(d,ArriveDate) END)As m3 ," 
strSQL = strSQL & "   COUNT (CASE  DATEPART(d,ArriveDate) WHEN 4 THEN DATEPART(d,ArriveDate) END)As m4 ,"    
strSQL = strSQL & " FROM Company "     
strSQL = strSQL & " WHERE DATEPART(yyyy,ArriveDate) =" & [Forms]![Raport_lunar_anual_carnete]![ANUL] &     
strSQL = strSQL & " AND DATEPART(mm,ArriveDate)= " & [Forms]![Raport_lunar_anual_carnete]![LUNA] &     
strSQL = strSQL & " GROUP BY DATEPART(yyyy,ArriveDate)"
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement