Re: HELP: problem updating table from table in same server



On Tue, 27 Mar 2007 19:03:20 -0700, John Steen
<moderndads(nospam)@hotmail.com> wrote:

I'm trying to update a table in one database with data from a table in
another database on the same server, but I'm having trouble with my naming
convention.

Here's the script:

update DB1.dbo.table1
set col1 = Db2.dbo.table1.col1
from DB1.dbo.table1
inner join
DB2.dbo.table1
on DB1.dbo.table1.col2 = DB2.dbo.table1.col2
where DB2.dbo.table1.col1 like
'textstring'

When I run it I get this error:

Server: Msg 7202, Level 11, State 2, Line 1
Could not find server 'lobbysqldbrawtest' in sysservers. Execute
sp_addlinkedserver to add the server to sysservers.

Hi John,

I don't see any 'lobbysqldbrawtest' in the code you posted. May I assume
that you simplified the code?

I'm sure it's because I'm using a 4-part name (Db2.dbo.table1.col1) and it's
trying to resolve the database as a server. I don't know of another way to
point to the database. Any suggestions?

In column names, you don't repeat the server name. In fact, the database
name can be omitted as well; just the table name is enough - though I
personally prefer to use an alias. In this case, with the table names
being equal, you actually *need* to use an alias!

UPDATE dest
SET col1 = src.col1
FROM DB1.dbo.table1 AS src
INNER JOIN DB2.dbo.table1 AS dest
ON src.col2 = dest.col2
WHERE src.col1 LIKE 'textstring';
(untested)

And since there are no wildcards in 'textstring', you can replace LIKE
with = to gain some performance.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.



Relevant Pages

  • RE: WSS install locked into MSDE DB - Can not install for SQL Serv
    ... For the MASTER database ... Althought we change the Configuration Application pool several times ... interface BUT they appear to be MSDE databases and not SQL Server databases. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: How to Replicate an SQL Server 2000 Database
    ... actual server name) enterprise manager should associate the database with the ... Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.replication)
  • Re: SQL 2005 Best Practice vs SQL 2000: Application Files Separate from data (and log) files
    ... I have had quite a number of clients that used a SAN for a database server and suffered significant performance problems because their underlying SAN infrastructure was a huge stripe across many drives. ... By application files I mean the binn folder which contains the sql server executable among other things. ...
    (microsoft.public.sqlserver.setup)
  • RE: SBS 2003 Unable to connect to database STS_Config
    ... Check the database connection information and make sure that the database ... Uninstall SQL Server; ... Reinstall Monitoring and Sharepoint and make sure they work; ...
    (microsoft.public.windows.server.sbs)
  • RE: Need help with copy database
    ... in the event log for the server SQL was running on. ... This was a username from the database ... SQL Server Agent service is run with a domain account that has full admin ... if @backupSetId is null begin raiserror(N''Verify failed. ...
    (microsoft.public.sqlserver.dts)