Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Hello - Export data from one catalog1-table1 to a catalog2-table2

$
0
0
Hello

I have a tabel in catalog "dbo.Users" and a table named "users" that I want to copy some fields from the "users" table into a different catalog, say "dbo.Catalog" and the table "users" in the dbo.Catalog.

So, something along these lines (I've tried multiple variations of this, temporary template, or #temptable and defining the temporary table outside...etc..

Code:

USE master
DECLARE @temptable TABLE (name nvarchar(5))

USE [Users]
GO
INSERT INTO @temptable(name)
(
        SELECT name FROM users
)

USE [Catalog2]
GO
INSERT INTO dbo.users(name)
(
        SELECT name from @temptable
)

SQL 2008, R2.
Suggestions are more than welcome.

Edit: Oh, maybe I can just insert it straigth into the table, something like this:
INSERT INTO Catalog.newUserTable (name)
VALUES
(
SELECT name FROM Users.user
)

Edit: Solved, worked like a charm, no need for the temporary table... Thanks for your time!

Viewing all articles
Browse latest Browse all 13329

Trending Articles