Home All Groups Group Topic Archive Search About

What is wrong with this SQL statement

Author
21 Oct 2005 7:46 AM
Steen Persson (DK)
Hi

When I run the query below in QA, it works fine and gives me some
results. When I try to run the same query in Microsoft Query from an
Excel sheet, it fails. I get the error "No column was specified for
column 1 of 'FSS'. Statements could not be prepared".

The query I try to run is this -

SELECT FF.FinFordelNr, FF.FordelingsSats,
FF.FinSelskabNr,FF.DatoGyldigPr FROM FinFordelSats FF
        JOIN (SELECT MAX(DatoGyldigpr) MaxDato, FinFordelNR FROM FinFordelsats
        GROUP BY (FinFordelNR)) FSS ON FF.DatoGyldigPr = FSS.MaxDato AND
FF.FinFordelNr = FSS.finFordelNr

(it's actually more than just this, but it's this single part that fails).

I'm not familiar with how Microsoft Query works from Excel, so it might
be very simple thing I'm missing.

Regards
Steen

Author
21 Oct 2005 8:11 AM
Jens
Try inserting an AS in this.

JOIN (SELECT MAX(DatoGyldigpr) AS MaxDato, FinFordelNR

HTH, Jens Suessmeyer.
Author
21 Oct 2005 8:22 AM
Steen Persson (DK)
Jens wrote:
> Try inserting an AS in this.
>
>  JOIN (SELECT MAX(DatoGyldigpr) AS MaxDato, FinFordelNR
>
> HTH, Jens Suessmeyer.
>
Sorry...I should of course have mentioned that I already tried that, but
  the result are the same. I've also tried to put the alias in ' ' ( AS
'MaxDato') which I can see has been done with the other column aliases
that have been created automatically by MS Query. I've also tried to
enter the full 3-part name (databasename.dbo.Tablename) which also seems
to be how MS Query is doing it, but that doesn't help either.

Regards
Steen

AddThis Social Bookmark Button