SQL SERVER 跨服务器连接

一、建立连接:

EXEC master.dbo.sp_addlinkedserver @server = N'gs', @srvproduct=N'get_kly', @provider=N'SQLOLEDB', @datasrc=N'192.168.0.145'

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'gs', @locallogin =NULL, @useself = N'False', @rmtuser = N'ls', @rmtpassword = N'xixihaha'

 

二、建立View

USE [UFPOS_DATA]
GO

/****** Object:  View [dbo].[V_GS_YCARD]    Script Date: 10/15/2012 22:04:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[V_GS_YCARD]
AS
SELECT     A.WBID, B.MFCRD_NAME
FROM         gs.get_kly.dbo.TWB_ACCESS_BATCH AS A WITH (NOLOCK) INNER JOIN
                      gs.get_kly.dbo.MFCRD_TBL AS B WITH (NOLOCK) ON A.WBID = B.MFCRD_CONTICNO
WHERE     (A.status = '0') AND (GETDATE() BETWEEN A.TckStartDate AND A.TckEndDate) AND (A.Gzone = '0')

GO

 

第三、查询视图

SELECT * FROM V_GS_YCARD

 

posted @ 2012-10-15 22:10  brian_lee  阅读(192)  评论(0编辑  收藏  举报