Please start any new threads on our new site at 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
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 tsql help with updating multiple rows
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 02/13/2013 :  18:42:37  Show Profile  Reply with Quote
i have a query as below.

1. i have a table in SAMINC database called ARCUS with column CODESLSP1
2. i need to update a table in CRM database called company with the value of CODESLSP1 in the column comp_sp
3. there are 1260 rows in table company

i tried a query as below but it fails as the sub query returns multiple rows
update company set comp_sp = (select CODESLSP1 from SAMINC.dbo.ARCUS INNER JOIN company ON SAMINC.dbo.ARCUS.IDCUST = comp_idcust COLLATE Latin1_General_BIN WHERE Comp_Deleted IS NULL)

please advise on how to best achieve and update multiple rows in company table from arcus table these both tables are in separate.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/13/2013 :  18:53:56  Show Profile  Reply with Quote
Which table has the column Comp_Deleted? In the following, I am assuming it is in the company table. If not change it to a.Comp_Deleted.
	c.comp_sp = a.CODESLSP1
	company c
		a.IDCUST = c.comp_idcust COLLATE Latin1_General_BIN
	c.Comp_Deleted IS NULL;
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/13/2013 :  23:30:16  Show Profile  Reply with Quote
Are both these dbs in same server? if yes above will work

Otherwise you've to set up linked server before you do update like above

SQL Server MVP

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