Search code examples
phpcoalesce

mssql_query(): message: Incorrect syntax near ',' --COALESCE


Hi i have problem witch part of sql query in php.

...
$sql.= " --COALESCE(SUM(CASE kontrole.zakres & 4 WHEN 0 THEN 0 ELSE 1 END),0) AS ADR,";
$sql.= " COALESCE(SUM(dbo._IS_ADR(kontrole.pojazd_key)),0) AS ADR,";
...

Generate error:

Warning: mssql_query(): message: Incorrect syntax near ','


Solution

  • You have an additional comma in the second SQL line that breaks the syntax in your query.

    ...
    $sql.= " --COALESCE(SUM(CASE kontrole.zakres & 4 WHEN 0 THEN 0 ELSE 1 END),0) 
    AS ADR,";
    $sql.= " COALESCE(SUM(dbo._IS_ADR(kontrole.pojazd_key)),0) AS ADR";
    ...