Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

T-SQL Temp Table Results Between Databases

Posted on 2016-11-24
2
Medium Priority
?
30 Views
Last Modified: 2016-11-24
Hello Experts,

This may be a silly question but I would like help with the following scenario.

Database 1
SELECT *
INTO #tmptable1
FROM table 1

[b][/Database 2b]
TRUNCATE TABLE X
INSERT INTO TABLE X
SELECT * FROM #tmptable1 in Database1
INTO TABLE X in Database2

Is this even possible?

Thanks
Infosec36
0
Comment
Question by:Sonia Bowditch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 1000 total points
ID: 41900498
Yup, it is. Exactly like that, assuming that you have sufficient privileges and no foreign constraints exist pointing to table X.
0
 
LVL 30

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 1000 total points
ID: 41900584
Yes it is possible in Single Session with proper access.

Also use 4 part name everytime.

Try something like..

--

SELECT * INTO #tmptable1
FROM servername.database1.schema.table1

TRUNCATE TABLE servername.Database2.schema.X

INSERT INTO TABLE servername.Database2.schema.X
SELECT * FROM #tmptable1

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question