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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update query - check if table exists

Author  Topic 

shpinoza1980
Starting Member

17 Posts

Posted - 2011-01-23 : 02:27:10
Hello,

How do I implement the 'If Exists' syntax in the following update query, to run the query only if tables exists in the database:

update t1 set t1.companyID = t3.companyID
from BRM_Events t1
join dbo.feeds t2 ON t1.feedID = t2.feedID
join dbo.companies t3 ON t2.companyName = t2.feedName


I need the if exists condition to check for t1,t2,t3 tables.

thanks a lot

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-01-23 : 03:59:15
IF OBJECT_ID('BRM_Events') IS NOT NULL AND OBJECT_ID('dbo.feeds') IS NOT NULL AND OBJECT_ID('dbo.companies') IS NOT NULL
UPDATE...



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

shpinoza1980
Starting Member

17 Posts

Posted - 2011-01-23 : 04:27:06
works great

thanks a lot
Go to Top of Page
   

- Advertisement -