SQLTeam.com | Weblogs | Forums

Update table with values from another one (only for results that have been previously generated)



Hello,i have the following problem:
2 tables on the same database
After filtering the the results with this statement:

SELECT * FROM z_icap_minim z, firme_ro
WHERE z.judet_Id <> firme_ro.judeteSiruta_Id AND z.cui = firme_ro.cui and firme_ro.StariFirme_Id=1

I get let's say 700 results based on all the criteria and StariFirme_Id=1 (1 is active in my case)

what i need to do is to update Tab1 with data from Tab2 but only for those 700 results

As update querry i was thinking at :

Update firme_ro_cami JOIN z_icap_minim
ON firme_ro_cami.CUI=z_icap_minim.CUI
SET firme_ro_cami.Adresa=z_icap_minim.Adresa

What i need is to use UPDATE only for those 700 results which were previously filtered (not for the entire Tab1 and Tab2) . Need to coonect these 2 querrys but i have no logic ideea how! Any help/advice?


Please test:

UPDATE firme_ro_cami
SET Adresa=z_icap_minim.Adresa
FROM firme_ro_cami
JOIN z_icap_minim ON firme_ro_cami.CUI=z_icap_minim.CUI
JOIN firme_ro ON z_icap_minim.judet_Id <> firme_ro.judeteSiruta_Id AND z.cui = firme_ro.cui
WHERE firme_ro.StariFirme_Id=1


Ty for the answear!

Error in syntax near line 3
"FROM firme_ro_cami"
this is what the console says!

I just cant figure it out how to do this only for those 700 results! it's frustrating :slight_smile:


I expect that you have not quoted the message precisely, but it sounds more like a MySQL error message than a Microsoft SQL Server one ?


It compiles for me in SQL Server Management Studio. Like Kristen said, you are probably not using Microsoft SQL Server which is what SQLTeam.com is all about. If you aren't using it, I'd suggest posting your question on a site that specializes in whatever technology you are using.