I currently use the following to data warehouse a table everday:
DROP TABLE mytable
SELECT firstcolumn, secondcolumn INTO mytable
FROM OPENQUERY (mylinkedserver, 'SELECT firstcolumn, secondcolumn FROM linkedtable')
I would like to start using TRUNCATE going forward (to perserve system resources and indexes):
TRUNCATE TABLE mytable
INSERT INTO mytable (firstcolumn, secondcolumn)
?
How do I use OpenQuery with the INSERT INTO statement?
I believe the syntax is:
TRUNCATE TABLE mytable
INSERT INTO mytable (firstcolumn, secondcolumn)
SELECT firstcolumn, secondcolumn
FROM OPENQUERY (mylinkedserver, 'SELECT firstcolumn, secondcolumn FROM linkedtable')
Did you try:
INSERT INTO mytable(firstcolumn, secondcolumn)
SELECT firstcolumn, secondcolumn
FROM OPENQUERY
(
mylinkedserver,
'SELECT firstcolumn, secondcolumn FROM linkedtable'
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.