Question

Today I wrote this bit of sql:

SELECT COUNT(T0021_werk_naam)
FROM (SELECT Distinct T0021_werk_naam,T0021_jaar,T0021_kwartiel
    FROM T0021_offertes
    WHERE T0021_status_code = 'G' AND T0021_jaar = 2013 AND (T0021_kwartiel = 3))

This sql runs great when I run it locally in access, however, when I run it through the code that has been used for ages for this and most certainly definetly is not the problem, and send it to SQL Express it gives an error that says there's a problem near ')'
After stripping away all the brackets possible it becomes clear that it detects there's a problem with the last ')' but I don't see the problem.

Any Ideas?

Était-ce utile?

La solution

You need to give an alias for the select in the parenthesis:

SELECT COUNT(T0021_werk_naam)
FROM   (
           SELECT Distinct T0021_werk_naam,
                  T0021_jaar,
                  T0021_kwartiel
           FROM   T0021_offertes
           WHERE  T0021_status_code = 'G' 
                  AND T0021_jaar = 2013 
                  AND (T0021_kwartiel = 3)
       ) T

notice the T in the end after the last parenthesis.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top