[英]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.