Re: Importing from another database on same server using SQL Server Express
- From: "Arnie Rowland" <arnie@xxxxxxxx>
- Date: Sun, 29 Oct 2006 19:04:06 -0800
Try one of these two choices, one using a JOIN, one using a Sub-SELECT:
UPDATE n
SET n.Field = o.Field
FROM NewDatabase.dbo.Table n
JOIN OldDatabase.dbo.Table o
ON n.PK = o.PK
(OR)
UPDATE NewDatabase.dbo.Table n
SET n.Field = (SELECT o.FIELD
FROM OldDatabase.dbo.Table o
WHERE o.Field = n.Field
)
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the top yourself.
- H. Norman Schwarzkopf
"John Hackert" <hackertjohnb@xxxxxxxxx> wrote in message news:1162174049.649530.85940@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I haven't been able to solve this likely syntax problem despite
referring to these groups, the Books On Line, and reference texts:
Without the use of Data Transformation Services in SQL Server Express,
what techniques work to import/export data between databases under the
same server instance?
The specific example I was working on involved an attempt to run an
update query to place data from a specific field in an older copy of an
otherwise identical database into a more recent copy. Ultimately I
just plugged the small data series in manually using side-by-side views
because I could not overcome the syntax errors generated in the effort
to refer to the "external" database.
This is the setup in question:
- An instance in the format of "MyComputerName\SQLExpress," and both an
- "OldDatabase" and
- "NewDatabase" attached and viewable from the Management Studio
Express, with identical fields
I tried a few different query techniques as suggested in historical
posts, but to no avail. Here is such an example that I tried:
In MSE I right clicked on the target table in question and chose:
"Script table as," then
"UPDATE to," then
"New Query Editor Window"
I removed all the fields except that in question and added this Where
clause:
UPDATE [NewDatabase].[dbo].[Table]
SET [Field] = [OldDatabase].[dbo].[Table].[Field]
WHERE [NewDatabase].[dbo].[Table].[PK] =
[OldDatabase].[dbo].[Table].[PK]
in which the primary key (an auto-increment integer) is identical
between the new and old tables.
This produces the error:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "OldDatabase.dbo.Table.PK" could not be
bound.
If I understood from prior posts, using joins is less desirable in
update queries, but even so likewise produced errors when I tried that
approach.
I would be grateful if someone could explain the proper syntax to refer
to another database within the same server instance or otherwise.
Many thanks!
- Follow-Ups:
- Re: Importing from another database on same server using SQL Server Express
- From: John Hackert
- Re: Importing from another database on same server using SQL Server Express
- References:
- Importing from another database on same server using SQL Server Express
- From: John Hackert
- Importing from another database on same server using SQL Server Express
- Prev by Date: Importing from another database on same server using SQL Server Express
- Next by Date: Replacing MSDE by SQL Server 2005
- Previous by thread: Importing from another database on same server using SQL Server Express
- Next by thread: Re: Importing from another database on same server using SQL Server Express
- Index(es):
Relevant Pages
|