简体   繁体   English

如何使用链接服务器中的存储过程将 int 传递给 OPEN QUERY?

[英]How can I pass an int into the OPEN QUERY using a stored procedure in a linked server?

I am trying to create a stored procedure using an OPEN QUERY for a linked server.我正在尝试使用 OPEN QUERY 为链接服务器创建存储过程。 I am having a problem on the Where Clause.我在 Where 子句上遇到问题。

I tried converting the where clause for the user id into varchar(10)我尝试将用户 ID 的 where 子句转换为 varchar(10)

DECLARE @user_id as bigint = 32

SELECT * FROM OPENQUERY(LMSBUILDER, 
  'SELECT       
     cc.id,cc.user_id,cc.title,cc.library_id
     ,cc.parameters,cc.filtered,cc.embed_type
     ,ll.name, ll.title as lib_title, ll.major_version
     ,ll.minor_version,ll.patch_version,ll.runnable
     ,ll.restricted,ll.fullscreen,ll.embed_types
     , ll.semantics 
   FROM 
      coursebuilder.wp_h5p_contents as cc 
      INNER JOIN coursebuilder.wp_h5p_libraries as ll 
        ON cc.library_id=ll.id 
   WHERE 
     cc.library_id IN (35,22, 34) 
     AND cc.user_id = '' + CONVERT(NVARCHAR(10), @user_id) + ''')

It should return all the results but instead I only got a null.它应该返回所有结果,但我只得到一个 null。 Whenever I try to run it in mysql it returns values每当我尝试在 mysql 中运行它时,它都会返回值

This duplicate link is resolve your answer.这个重复的链接是解决你的答案。

Microsoft Support How to pass a variable to a linked server query is also resolve your issue. Microsoft 支持如何将变量传递给链接服务器查询也可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过查询将参数传递给存储过程? - How can I pass parameter to stored procedure through a query? 我在做什么错:使用开放查询功能从sql server执行了oracle存储过程 - What am I doing wrong: executed an oracle stored procedure from sql server using the open query function 如何在链接服务器中获取存储过程的定义? - How to get the definition of a stored procedure in a Linked Server? 如何在存储过程中将DateTime格式传递给MS sql服务器? - How can I pass DateTime format to MS sql server in a stored procedure? 如何仅将时间参数传递给SQL Server中的存储过程 - How can I pass only time parameter to a stored procedure in SQL Server 如何使用传递查询在if语句中调用存储过程? - How to call a stored procedure in an if statement using pass through query? 如何使用我传递的参数使存储过程返回“数据集”? - How can I make a stored procedure return a “dataset” using a parameter I pass? SQL Server:如何在存储过程中使用游标执行查询以及如何将参数列表传递给存储过程 - SQL Server: how to execute query with cursor inside stored procedure and how to pass a list of params to the stored procedures 如何将字符串类型值传递给存储过程? - How can I pass a string type value into a Stored Procedure? 如何将主体从存储过程传递到 REST 服务? - How can I pass a body from stored procedure to a REST service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM