Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 T-SQL UPDATE JOIN Two Tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lesponce
Starting Member

8 Posts

Posted - 12/06/2012 :  19:57:02  Show Profile  Reply with Quote
I need to update a field with value '1' on Table A, but I need to join to Table B to check if the customer that I'm going to update on table A, exists on Table B. If the customer does not exist on table B, then I can't update Table A.

How do I do that?

On Table A I'm going to set FLAG = '1'
WHERE FLAG on TABLE A is NULL and Does exists on TABLE B

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 12/06/2012 :  20:22:38  Show Profile  Reply with Quote
UPDATE a
SET FLAG = '1'
FROM tableA a
WHERE EXISTS
(select * from tableB b where a.customer = b.customer)
AND FLAG is null

Jim

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000