database/mssql

open query

labj 2012. 3. 22. 01:07

--****************************

--* Example 1
--* Import all users into new table
--*****************************/
SELECT *
INTO dbo.Users_Import
FROM OPENQUERY(remotelinkedservername, 'SELECT * FROM dbo.Users' )
  
--****************************
--* Example 2
--* Insert users that do not exist
--* into existing table
--*****************************/
INSERT INTO dbo.Users
(
    UserID,
    UserName,
    FirstName,
    LastName
)
SELECT
    UserID,
    UserName,
    FirstName,
    LastName
FROM OPENQUERY(remotelinkedservername, 'SELECT * FROM dbo.Users' ) ru
WHERE NOT EXISTS
(
    SELECT 1
    FROM dbo.Users
    WHERE UserID = ru.UserID
)
  
--/****************************
--* Example 3
--* Insert results from remote procedure
--* into new table
--*****************************/
SELECT *
INTO dbo.List
FROM OPENQUERY(remotelinkedservername, 'set fmtonly off exec dbo.GetList')

'database > mssql' 카테고리의 다른 글

MSSQL 버전 확인  (0) 2012.03.22
(Transact-SQL)  (0) 2012.03.22
특정 테이블 컬럼명 가져오기  (0) 2012.03.22
MSSQL 2005 Express 외부 접속  (0) 2012.03.22
SQL Server Management Studio Express 인스턴스명  (0) 2012.03.22