Solved

T-SQL Temp Table Results Between Databases

Posted on 2016-11-24
2
11 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:infosec36
2 Comments
 
LVL 32

Accepted Solution

by:
ste5an earned 250 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 17

Assisted Solution

by:Pawan Kumar Khowal
Pawan Kumar Khowal earned 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now