openquery

Openquery with variables in datetime using like clause with linked server

北城余情 提交于 2019-12-11 15:36:44
问题 Everytime I execute this query I get this error: The data types varchar and varchar are incompatible in the modulo operator. Asking for your help. Thanks! DECLARE @date datetime, @SQL NVARCHAR(MAX); SET @date = '2019'; SET @SQL = 'SELECT * FROM OPENQUERY(LINK2, ''SELECT * FROM wordpress.wp_users WHERE user_registered LIKE '''%' +@date+ '%''''')'; EXEC sp_executesql @SQL; 回答1: you can be varchar(4) because you are setting it as string. then use datepart() DECLARE @date varchar(4), @SQL

How to make your Server as Linked Server for selected views?

天大地大妈咪最大 提交于 2019-12-11 15:16:52
问题 We have a SQL Server 2012 instance which is the database for our security system. Now we have a scenario where we want to allow another team our SQL Server to select certain records, ie we created four views for them for their requirements. But, we don't want to provide or list all our tables to them but only allow these four views to see and query in our system. As I go through many documents it's clear that we can do it through making our SQL Server as a linked server. What's the best way

OPENQUERY throws error when used with WIN2K8\SQL2K12

浪尽此生 提交于 2019-12-11 14:13:40
问题 I'm trying the following Sql query to move my stored procedure result into table SELECT * INTO #tmpTable FROM OPENQUERY(WIN2K8\SQL2K12, 'EXEC vcs_gauge @gauge_name=vs1_bag,@first_rec_time=2014-09-01 09:00:00,@last_rec_time=2014-09-01 10:00:00') following error is thrown, when I execute the query. Incorrect syntax near '\'. I don't want to add linked server .How to resolve this issue? EDIT1 When I do [win2k8\sql2k12], and first execute the following command EXEC sp_serveroption 'YourServer',

Insert into table on the Linked Server with data from local table

。_饼干妹妹 提交于 2019-12-10 17:32:52
问题 I'm working with SQL Server Express, I created a linked server to an Oracle database. As the title indicates, I want to insert data selected from a local table into a table at the Linked Server. I tried many queries but no one of them worked as I want. This query below I used has worked, but only with static values, but I want to insert data dynamically from the a table on local database. INSERT OPENQUERY (ORTEST, 'SELECT * FROM reservation') VALUES (2, '2', 3); 回答1: It is normal that it

How to Set a variable using OPENQUERY in SQL Server

泄露秘密 提交于 2019-12-08 03:57:34
问题 I am trying to read data from a table. This table have a list of table name. for each row of the data set I want to run a couple of queries to pull data and insert it into a temporary table. Here is What I have done DECLARE @campName varchar(255); DECLARE @sqlCommand varchar(1000); DECLARE @sqlCommandMySQL varchar(1000); DECLARE @LastRun varchar(60); DECLARE @OPENQUERY varchar(1000); DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT LTRIM(RTRIM(CallListName)) AS

How to Set a variable using OPENQUERY in SQL Server

牧云@^-^@ 提交于 2019-12-06 09:38:56
I am trying to read data from a table. This table have a list of table name. for each row of the data set I want to run a couple of queries to pull data and insert it into a temporary table. Here is What I have done DECLARE @campName varchar(255); DECLARE @sqlCommand varchar(1000); DECLARE @sqlCommandMySQL varchar(1000); DECLARE @LastRun varchar(60); DECLARE @OPENQUERY varchar(1000); DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT LTRIM(RTRIM(CallListName)) AS CallListName FROM [SMSQL1].[RDI_System].[dbo].[Campaigns] WHERE dialer_campaign = 1 AND i3Server ='I3New' AND

How to test linkedserver's connectivity in TSQL

北城余情 提交于 2019-12-04 13:38:31
问题 I need to write a procedure to collect data from several remote servers, I use linkedservers and OPENQUERY to gather data from servers, but sometimes I lose connection to some servers or I simply can't connect them (e.g. remote server is offline)- and OPENQUERY results in time-outs in these cases. So I wanted to check linkedservers connectivity first and then if it's successful run the query, if not just move on to next the remote server. I tried to put OPENQUERY in TRY - CATCH but it still

How to join linked server table and sql server table while using openquery

冷暖自知 提交于 2019-12-04 08:49:29
I use openquery syntax to read the data from a linked server. SELECT * FROM OPENQUERY(LinkServer, 'SELECT * FROM Product') I want to join this link server table with an Sql server table to get my final results. For now I do it by, having a temp table. SELECT * INTO #Temp_Products FROM OPENQUERY(TREPO, 'SELECT ID, Name FROM Products') SELECT * FROM #TEMP_PRODUCTS A INNER JOIN ORDERED_PRODUCTS B ON A.ID = B.ID But as the link server product table contains huge records, it takes time to get filled into the temp table. So I think instead of pulling all product information, If I join both the

Using OPENQUERY with an Oracle database to query a date range

橙三吉。 提交于 2019-12-04 04:54:06
问题 We have an Oracle database that we access through OpenQuery for some stuff. You apparently can't do date comparisons directly in OpenQuery using the OleDB driver, so to get around this you have to convert the dates to Julien dates and compare those numbers. I have the following query that we're trying to execute this in MS SQL Server (GPROD is a Linked Server via the OleDb driver): SELECT * FROM OPENQUERY(GPROD, ' SELECT * FROM ORD_HDR_HST WHERE (cast(to_number(to_char(SHIP_DATE ,''J'')) as

Linked server dynamic catalog for executing MDX through OpenQuery

允我心安 提交于 2019-12-02 15:43:26
问题 I have multiple OLAP databases in my project, so is it possible to dynamically decide the catalog for executing this MDX query? SELECT * FROM OpenQuery(OLAP_SERVER, 'WITH MEMBER measures.X AS dimensions.count SELECT Measures.X ON 0 FROM MyCube') as X I don't want to create a separate linked server for each of the OLAP database. Both the relational and cube databases reside on the same physical machine. My linked server configuration are: EXEC master.dbo.sp_addlinkedserver @server = N'OLAP