Groups | Blog | Home
all groups > sql server msde > october 2006 >

sql server msde : Importing from another database on same server using SQL Server Express


John Hackert
10/29/2006 6:07:29 PM
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!
Arnie Rowland
10/29/2006 7:04:06 PM
Try one of these two choices, one using a JOIN, one using a Sub-SELECT:

UPDATE n
SET n.Field =3D o.Field
FROM NewDatabase.dbo.Table n
JOIN OldDatabase.dbo.Table o
ON n.PK =3D o.PK

(OR)

UPDATE NewDatabase.dbo.Table n
SET n.Field =3D (SELECT o.FIELD
FROM OldDatabase.dbo.Table o
WHERE o.Field =3D n.Field
)

--=20
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.=20
Most experience comes from bad judgment.=20
- Anonymous

You can't help someone get up a hill without getting a little closer to =
the top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]
John Hackert
10/30/2006 11:19:51 AM
Thank you for replying -

Even with these other techniques, I receive the same "multi-part
identifier...could not be bound" error. So, perhaps the root of the
problem is not the syntax of the query but something else. Any other
ideas?

John H


[quoted text, click to view]
Hugo Kornelis
11/3/2006 11:31:12 PM
[quoted text, click to view]

Hi John,

Please post the COMPLETE query, and the COMPLETE error message. Use copy
and paste to prevent errors. That information can help us pinpoint the
problem.

--
John Hackert
11/4/2006 1:03:43 PM
Thank you for replying

I thought this post was considered dead, so I elected to repost the
question on microsoft.public.sqlserver.server. The syntax proposed by
"amish" on that group proved to work:

UPDATE [TestNew].[dbo].[tblProcedure]
SET [CPT] = TestOld.[CPT]
FROM [TestNew].[dbo].[tblProcedure] TestNew inner join
[TestOld].[dbo].[tblProcedure] TestOld
on
TestNew.[procedureID]=TestOld.[procedureID]



[quoted text, click to view]
Hugo Kornelis
11/5/2006 10:07:41 PM
[quoted text, click to view]

Hi John,

I'm glad to hear that you have managed to get this sorted out!

--
AddThis Social Bookmark Button