openquery

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 overcome “Failure getting record lock on a record from table”?

▼魔方 西西 提交于 2020-01-05 04:28:05
问题 I am running a query using OpenQuery and getting a peculiar error. This is my query: select * from OpenQuery("CAPITAOC",'SELECT per.* FROM pub."re-tenancy" AS t INNER JOIN pub."re-tncy-person" AS per ON t."tncy-sys-ref" = per."tncy-sys-ref" INNER JOIN pub."re-tncy-place" AS place ON t."tncy-sys-ref" = place."tncy-sys-ref" WHERE t."tncy-status" = ''CUR'' and place."place-ref"=''GALL01000009''') This is the error message: OLE DB provider "MSDASQL" for linked server "CAPITAOC" returned message "

SQL Server 2012 - Insert into linked server table using openquery

醉酒当歌 提交于 2020-01-03 16:02:08
问题 I have a linked server Remoteserver containing a table that holds file and folder names from a dir When I am on the remote server I can run a built in procedure ( xp_dirtree ) and populate the 'files' table but what i need to do is to run a query from the local SQL server that does this: Delete all records from the [Files] table on Remoteserver Insert data that comes from the stored procedure: INSERT [Remoteserver].[dbo].[files] (subdirectory,depth,isfile) EXEC master.sys.xp_dirtree '\

SQL Server 2012 - Insert into linked server table using openquery

夙愿已清 提交于 2020-01-03 16:02:05
问题 I have a linked server Remoteserver containing a table that holds file and folder names from a dir When I am on the remote server I can run a built in procedure ( xp_dirtree ) and populate the 'files' table but what i need to do is to run a query from the local SQL server that does this: Delete all records from the [Files] table on Remoteserver Insert data that comes from the stored procedure: INSERT [Remoteserver].[dbo].[files] (subdirectory,depth,isfile) EXEC master.sys.xp_dirtree '\

Slow query when connecting to linked server

*爱你&永不变心* 提交于 2019-12-23 07:53:05
问题 I've got this query UPDATE linkeddb...table SET field1 = 'Y' WHERE column1 = '1234' This takes 23 seconds to select and update one row But if I use openquery (which I don't want to) then it only takes half a second. The reason I don't want to use openquery is so I can add parameters to my query securely and be safe from SQL injections. Does anyone know of any reason for it to be running so slowly? 回答1: Here's a thought as an alternative. Create a stored procedure on the remote server to

Slow query when connecting to linked server

我怕爱的太早我们不能终老 提交于 2019-12-23 07:52:15
问题 I've got this query UPDATE linkeddb...table SET field1 = 'Y' WHERE column1 = '1234' This takes 23 seconds to select and update one row But if I use openquery (which I don't want to) then it only takes half a second. The reason I don't want to use openquery is so I can add parameters to my query securely and be safe from SQL injections. Does anyone know of any reason for it to be running so slowly? 回答1: Here's a thought as an alternative. Create a stored procedure on the remote server to

Execute stored proc with OPENQUERY

只谈情不闲聊 提交于 2019-12-21 16:21:19
问题 I have SQL Server 2008 with a linked Sybase server and I am trying to execute a stored procedure on the Sybase server using OPENQUERY. If I have a stored proc that doesn't take parameters it succeeds fine. If I have a stored proc with parameters it fails. I even tried a very basic stored proc that only took an int an that still failed. Below is the syntax I am using: select * from OPENQUERY([LINKSERVER],'exec database.user.my_stored_proc ''AT'',''XXXX%'',''1111'',1') Msg 7357, Level 16, State

Why is using OPENQUERY on a local server bad?

喜夏-厌秋 提交于 2019-12-21 01:26:05
问题 I'm writing a script that is supposed to run around a bunch of servers and select a bunch of data out of them, including the local server. The SQL needed to SELECT the data I need is pretty complicated, so I'm writing sort of an ad-hoc view, and using an OPENQUERY statement to get the data, so ultimately I end up looping over a statement like this: exec('INSERT INTO tabl SELECT * FROM OPENQUERY(@Server, @AdHocView)') However, I've heard that using OPENQUERY on the local server is frowned upon