linked-server

SQL Server: is it possible to get data from another SQL server without setting linked server?

蹲街弑〆低调 提交于 2021-02-16 20:47:31
问题 I need to do the following query (for example): SELECT c1.CustomerName FROM Customer as c1 INNER JOIN [ExternalServer].[Database].[dbo].[Customer] as c2 ON c2.RefId = c1.RefId For some security reason my client doesn't allow me to create a linked server. The user under whom I execute this query has access to both tables. Is it possible to make it work without using linked server? Thanks. 回答1: You could use OPENROWSET, which'll require the connection info, username & password... While I

Capture Linked server queries using SQL Extended Events

混江龙づ霸主 提交于 2021-02-08 05:37:41
问题 I tried many event types but could not achieve logging for Linked server. I could figure out events for all other databases but no luck with linked server. Any suggestions ? 回答1: You can use the OLEDB_DATA_READ event to track queries to linked servers. If the results from this event are more verbose than you want, you may need to add filters to capture the the particular information that is needed. The following DDL creates this extended event and adjusting the options (i.e. FILENAME , MAX

How to query against multiple linked servers?

若如初见. 提交于 2021-02-07 18:23:30
问题 After linking some SQL Server 2008 Servers / instances, I would like to do a more generic query against these servers. I know that I must specify the destiny of the query like that: select * from [SRV\INSTANCE].dbname.dbo.foo But, I would run this query against more than one linked server. I know also that this select statement returns exactly the SRV\INSTANCE that I need: select ss.name from sys.servers ss where ss.server_id > 0 This one, returns all servers\instances from where I want query

How to query against multiple linked servers?

一世执手 提交于 2021-02-07 18:23:25
问题 After linking some SQL Server 2008 Servers / instances, I would like to do a more generic query against these servers. I know that I must specify the destiny of the query like that: select * from [SRV\INSTANCE].dbname.dbo.foo But, I would run this query against more than one linked server. I know also that this select statement returns exactly the SRV\INSTANCE that I need: select ss.name from sys.servers ss where ss.server_id > 0 This one, returns all servers\instances from where I want query

Escape single quote in openquery using dynamic query

北慕城南 提交于 2021-02-07 13:47:58
问题 I need to retrieve data from a linked server using a parameter, @PickedDate for example. The query works fine if I skip @A and @B, but it always returns an error due to a missing single quote. Please advise, thanks. The query: Declare @OPENQUERY nvarchar(500), @TSQL nvarchar(max), @LinkedServer nvarchar(20), @A varchar(5), @B varchar(5), @PickedDate varchar(8) Set @PickedDate = '20150501' Set @A = 'AAA' Set @B = 'BBB' Set @LinkedServer = 'LinkedServerName' Set @OPENQUERY = 'Select * From

Escape single quote in openquery using dynamic query

会有一股神秘感。 提交于 2021-02-07 13:47:06
问题 I need to retrieve data from a linked server using a parameter, @PickedDate for example. The query works fine if I skip @A and @B, but it always returns an error due to a missing single quote. Please advise, thanks. The query: Declare @OPENQUERY nvarchar(500), @TSQL nvarchar(max), @LinkedServer nvarchar(20), @A varchar(5), @B varchar(5), @PickedDate varchar(8) Set @PickedDate = '20150501' Set @A = 'AAA' Set @B = 'BBB' Set @LinkedServer = 'LinkedServerName' Set @OPENQUERY = 'Select * From

Escape single quote in openquery using dynamic query

倖福魔咒の 提交于 2021-02-07 13:47:02
问题 I need to retrieve data from a linked server using a parameter, @PickedDate for example. The query works fine if I skip @A and @B, but it always returns an error due to a missing single quote. Please advise, thanks. The query: Declare @OPENQUERY nvarchar(500), @TSQL nvarchar(max), @LinkedServer nvarchar(20), @A varchar(5), @B varchar(5), @PickedDate varchar(8) Set @PickedDate = '20150501' Set @A = 'AAA' Set @B = 'BBB' Set @LinkedServer = 'LinkedServerName' Set @OPENQUERY = 'Select * From

How to send an e-mail from database if some condition is met?

心不动则不痛 提交于 2020-07-23 08:18:06
问题 I am beginner. We have: database, schema, tablename Table contain columns: Number , State , ExportTime , ImportTime I need to create a procedure which will send an email from the database (MSSQL) to my mailbox if the amount of the records is bigger than 5 (for records where State=2). That e-mail must contain all rows of that table (if condition is met) in descending order. Then, the procedure must be performed every hour as a job and connect to server using Linked Server... I know only how to

How to send an e-mail from database if some condition is met?

懵懂的女人 提交于 2020-07-23 08:16:17
问题 I am beginner. We have: database, schema, tablename Table contain columns: Number , State , ExportTime , ImportTime I need to create a procedure which will send an email from the database (MSSQL) to my mailbox if the amount of the records is bigger than 5 (for records where State=2). That e-mail must contain all rows of that table (if condition is met) in descending order. Then, the procedure must be performed every hour as a job and connect to server using Linked Server... I know only how to