-1

The code looks like this but it shows me multipart identifier loty and users could not be found

UPDATE zabukowane
SET cenabiletu = zabukowane.cenabagazu + loty.cena
WHERE zabukowane.idlotu = loty.idlotu AND zabukowane.userid = users.userid
FROM zabukowane JOIN loty, users;

I want to set column(cenabiletu) in zabukowane to take from table called loty column cena where usersid in users is equal to userid in zabukowane and idlotu in loty is equal to idlotu in zabukowane and adding to cenabagazu and summing that up in cenabiletu column so it may look like this cenabiletu.zabukowane=cena.loty+cenabagazu.zabukowane

Nycolas Silvestre
  • 1,445
  • 1
  • 10
  • 13
  • 2
    `FROM` goes *before* the `WHERE`, not afterwards. You are also lacking a `ON` for your `JOIN` and are mix and matching ANSI-89 and ANSI-92 JOIN syntax; stick to ANSI-92. – Thom A Nov 11 '22 at 15:56
  • 1
    It also seems that there are a bit too many (unnecessary) tags - [c#] for instance seems unrelated – Rafalon Nov 11 '22 at 16:01
  • sory for taggin too much but to post i needed 5 and i use stackoverflow for first time – Oskar Kacala Nov 11 '22 at 16:04

1 Answers1

0

Seems that you are missing a few points. Try it in this way:

UPDATE zabukowane
SET cenabiletu = zabukowane.cenabagazu + loty.cena
FROM zabukowane 
INNER JOIN loty on  zabukowane.idlotu = loty.idlotu
Jo
INNER JOIN users on zabukowane.userid = users.userid

This post question gmhas a great explanation: How do I UPDATE from a SELECT in SQL Server?.

Nycolas Silvestre
  • 1,445
  • 1
  • 10
  • 13