SQL Server Forums
Profile | Register | 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
 New Topic  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
52317 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  
 New 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