Pergunta

I am trying to run this query but fail :

procedure TForm4.FormShow(Sender: TObject);
begin
with ClientDataSet1 do
begin
ClientDataSet1.Close;
ClientDataSet1.CommandText :='';
ClientDataSet1.CommandText :='select lokacije.[LOKACIJA_ID],lokacije.[RESORT_ID],'
+ 'lokacije.[HOTEL_ID],lokacije.[NAZIV],'
+ 'uporabniki.[RESORT_ID],uporabniki.[HOTEL_ID],uporabniki.[LOKACIJA_ID],'
+ 'uporabniki.[UPORABNIK],uporabniki.[GESLO],uporabniki.[PRAVICE] from LOKACIJE'
+ 'inner join UPORABNIKI on lokacije.[LOKACIJA_ID]=uporabniki.[LOKACIJA_ID]'
+ 'where lokacije.[NAZIV] = ''' + Form2.AdvOfficeStatusBar1.Panels[3].Text + ''' '
+ 'ORDER BY Uporabniki.[UPORABNIK]';
ClientDataSet1.Open;
end;
end;

I get the error : "Remote error: No such table :LOKACIJEinner"

What am I missing here ??? Database is SQLite. The form that I am opening here is a modal one.The whole app is a datasnap one.This is Client side. Problem is actually this : I have many locations and I only need the data from the name of the location displayed by AdvOfficeStatusBar1.Panels[3].Text.

Foi útil?

Solução

I think that this is more readable

procedure OpenLokacije(ANaziv: String);
begin
   ClientDataSet1.Close;
   ClientDataSet1.CommandText :=  ' select lokacije.[LOKACIJA_ID],'+    // AS Lok_LOKACIJA_ID
                                  '        lokacije.[RESORT_ID],'+
                                  '        lokacije.[HOTEL_ID],'+
                                  '        lokacije.[NAZIV],'+
                                  '        uporabniki.[RESORT_ID],'+
                                  '        uporabniki.[HOTEL_ID],'+
                                  '        uporabniki.[LOKACIJA_ID],'+ // AS Upor_LOKACIJA_ID
                                  '        uporabniki.[UPORABNIK],'+
                                  '        uporabniki.[GESLO],'+
                                  '        uporabniki.[PRAVICE]'+
                                  ' from LOKACIJE'+
                                  '         inner join UPORABNIKI on lokacije.lokacija_id=uporabniki.lokacija_id '+
                                  ' where lokacije.[NAZIV] = :@NAZIV'+
                                  ' order by Uporabniki.[UPORABNIK]';
 ClientDataSet1.Parameters.ParamByName('@NAZIV').Value:= ANaziv;
 ClientDataSet1.Open;
end;

lokacije.lokacija_id and uporabniki.lokacija_id are the same value and field respectively.

use AS:

lokacije.lokacija_id as lok_lokacija_id
uporabniki.lokacija_id  as  upo_lokacija_id

Also use the schema of the database like

dbo.uporabniki.lokacija_id
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top