I’m writing a database query that will show me where there is a space for parking. It is only used in July.
There is one table that shows all the spaces and whether they are rented that day. There is another table that has the spaces and their sizes. I want to be able to select those spaces that are available on all the days within the selected time period and have the correct size.
I am having a problem, though, selecting only the spaces available within the given time period. Here is the query so far but it does not contain anything concerning the space size as I want this part to work first.
SELECT C.Plads, SUM[C.optaget] C.[ledlig] FROM
(SELECT Plads FROM OptagetPladser AS A Inner JOIN Bådpladser as B ON
A.plads=B.Pladsnummer
WHERE
(A.dato>=" + Startdato + "and A.dato<="+Slutdato+") //checking the time period
and (a.optaget = 0)) //0 means the space is availible
as C
GROUP BY C.Plads
HAVING SUM(C.optaget) >="+ diffResult+")";//diff result is the timespan
At the moment I’m getting the error
Syntax error (missing operator) in query expression ‘SUM[C.optaget]’
Any ideas?
First of all, you should rework your SQL query – it contains too many simple errors.
Here are a few.
Try adding a ‘,’ and make some changes in query:
SELECT C.Plads, SUM(C.optaget), C.ledlig FROMYour subquery
Cdoesn’t have anoptagetandledligfields too. To fix this add those fields right after sebquery’sSELECTFix a syntax error here:
(A.dato>=" + Startdato + "and A.dato<="+Slutdato+")which should be:(A.dato >= " + Startdato + " and A.dato <= "+Slutdato+")Your last double quote is redundant as well as last ‘)’. Remove it:
HAVING SUM(C.optaget) >= "+ diffResult+" ;//diff result is the timespanBelow is how your SQL query should look. Please, note: there are still missing fields
optagetandledligin subqueryC.I believe, there could appear an architectural or performance issues, but without table data I can’t say it for sure.