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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 check key exist
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nirnir
Starting Member

10 Posts

Posted - 10/16/2013 :  05:53:39  Show Profile  Reply with Quote
I have two tables

TableA
key :char[20]
data:char[100]

TableB
kay :char[20]
existInTableA : bit

I need to update existInTableA field in each record of tableB
to indicate if tableA contains record with same key
what is the best way to do that ?

attached sample data

TableA
-----------
key1,data1
key2,data2
key4,data4

TableB
----------
key1,true
key2,true
key3,false
key4,true



visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 10/16/2013 :  08:01:27  Show Profile  Reply with Quote

UPDATE b
SET existInTableA = 1
FROM TableB b
WHERE EXISTS (SELECT 1 FROM TableA WHERE key = b.key)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.03 seconds. Powered By: Snitz Forums 2000