14. januar 2010 - 14:30Der er
10 kommentarer og 1 løsning
Jet SQL query med join subselect giver non updateable query fejl
Hej,
Flg. SQL query virker fint i Transact SQL, men overfoert til Jet SQL (Access) giver den en fejl. Det er ikke et spoergsmaal om skriverettigheder, men jeg kan forstaa at man ikke kan bruge subselects med join i en Update.
Her er SQL'en:
update familia set suprabrandid = (select marca.suprabrandid from producto inner join marca on marca.id = producto.idmarca where producto.idfamilia = familia.id and (producto.active = 1 OR producto.active = -1))
qryMarcaProducto: SELECT marca.suprabrandid, producto.idfamilia FROM producto INNER JOIN marca ON producto.idmarca = marca.id WHERE (((producto.active)=1 Or (producto.active)=-1));
SQL: UPDATE familia INNER JOIN qryMarcaProducto ON familia.id = qryMarcaProducto.idfamilia SET familia.suprabrandid = [marca].[suprabrandid];
Silly that this is necessary, why shouldnt a subselect work?
It would (Maybe (to cover myself :o))) also be possible to do it all in one SQL by having the SQL in qryMarcaProducto return a derived table (TEMP table) and joining on this in the UPDATE SQL.
Ok, Terry, your suggestion worked, but since I had to create it all through SQL I'm just going to post the final solution:
CREATE VIEW qryMarcaProducto (suprabrandid, idfamilia) as SELECT marca.suprabrandid, producto.idfamilia FROM producto INNER JOIN marca ON producto.idmarca = marca.id WHERE (((producto.active)=1 Or (producto.active)=-1));
UPDATE familia INNER JOIN qryMarcaProducto ON familia.id = qryMarcaProducto.idfamilia SET familia.suprabrandid = qryMarcaProducto.suprabrandid;
It seems that quite a few users have problems with giving points. You should be able to select from a list of those who have placed an answer whichI have d. 15. januar 2010 kl. 11:28:22
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.