[英]Conversion failed when converting the nvarchar value to datatype int
I have this two stored procedure that return data: 我有这两个返回数据的存储过程:
ALTER proc [dbo].[spBuscarUrl]
@CodigoContrato nvarchar(255),
@url nvarchar(255) OUTPUT
AS
SET NOCOUNT ON;
SELECT @url = url
FROM v_compras_y_contrataciones AS cc
WHERE CodigoContrato = @CodigoContrato;
RETURN
When I'm trying to return the value for the second stored procedure, the error says: 当我尝试返回第二个存储过程的值时,错误提示:
ALTER procedure [dbo].[spCaller]
AS BEGIN
DECLARE @URL nvarchar(255);
EXECUTE spBuscarUrl
'MIREX-2017-00001', @url = @URL OUTPUT;
RETURN convert(nvarchar(255),@URL);
END
Msg 245, Level 16, State 1, Procedure spCaller, Line 6 Conversion failed when converting the nvarchar value ' https://comunidad.comprasdominicana.gob.do//Public/Tendering/OpportunityDetail/Index?noticeUID=DO1.NTC.2 ' to data type int. 消息245,级别16,状态1,过程spCaller,第6行转换nvarchar值' https://comunidad.comprasdominicana.gob.do//Public/Tendering/OpportunityDetail/Index?noticeUID=DO1.NTC.2时转换失败'为数据类型int。
The problem is this line in spCaller
: 问题是
spCaller
这一行:
RETURN convert(nvarchar(255),@URL);
The RETURN
statement can only return INT
, not NVARCHAR
. RETURN
语句只能返回INT
,而不能返回NVARCHAR
。 If you want to return anything from a Stored Produre that is not an INT you need to either use an output parameter or SELECT
. 如果要从存储产品返回不是INT的任何内容,则需要使用输出参数或
SELECT
。
If you want to return a value, use a function. 如果要返回值,请使用一个函数。 In this case, though, you can't do that because of the
execute
. 但是,在这种情况下,由于
execute
,您将无法execute
。 So use an output parameter: 因此,使用输出参数:
CREATE FUNCTION [dbo].[spCaller] (
out_url nvarchar(255) output
) AS
BEGIN
EXECUTE spBuscarUrl 'MIREX-2017-00001', @url = @out_URL OUTPUT;
END;
Based on your execute
statement, you seem to know how to call such a stored procedure. 根据您的
execute
语句,您似乎知道如何调用这样的存储过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.