Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 当不使用int时,int与uniqueidentifier不兼容_Sql_Sql Server - Fatal编程技术网

Sql 当不使用int时,int与uniqueidentifier不兼容

Sql 当不使用int时,int与uniqueidentifier不兼容,sql,sql-server,Sql,Sql Server,当在任何地方都绝对没有使用int时,我得到了这个错误 我有这个存储过程 ALTER procedure [dbo].[usp_GetFileGuid] @fileType varchar(25) as select [id] from fileTypes where dirId = @fileType 此处id是文件类型表中的唯一标识符 当我执行以下命令时 declare @fileGuid uniqueidentifier exec @fileGuid = usp_GetFile

当在任何地方都绝对没有使用int时,我得到了这个错误

我有这个存储过程

 ALTER procedure [dbo].[usp_GetFileGuid] @fileType varchar(25)
 as 
 select [id] from fileTypes where dirId = @fileType
此处id是文件类型表中的唯一标识符

当我执行以下命令时

 declare @fileGuid uniqueidentifier
 exec @fileGuid = usp_GetFileGuid 'accounts'
 print @fileGuid
我得到以下错误

 (1 row(s) affected)
 Msg 206, Level 16, State 2, Procedure usp_GetFileGuid, Line 0
 Operand type clash: int is incompatible with uniqueidentifier
将存储过程的输出赋值给局部变量的语法有什么错误吗?谢谢。

您使用的是EXEC@fileGuid=过程语法,用于检索返回值,而不是结果集。返回值限制为INT,只能用于返回状态/错误代码,不能用于返回数据

您要做的是使用输出参数:

ALTER procedure [dbo].[usp_GetFileGuid] 
  @fileType varchar(25),
  @id UNIQUEIDENTIFIER OUTPUT
AS
BEGIN
  SET NOCOUNT ON;
  SELECT @id = [id] from dbo.fileTypes where dirId = @fileType;
  -- if the procedure *also* needs to return this as a resultset:
  SELECT [id] = @id;
END
GO
然后使用:

declare @fileGuid uniqueidentifier;
exec dbo.usp_GetFileGuid @fileType = 'accounts', @id = @fileGuid OUTPUT;
print @fileGuid;
您正在使用EXEC@fileGuid=过程语法,该语法用于检索返回值,而不是结果集。返回值限制为INT,只能用于返回状态/错误代码,不能用于返回数据

您要做的是使用输出参数:

ALTER procedure [dbo].[usp_GetFileGuid] 
  @fileType varchar(25),
  @id UNIQUEIDENTIFIER OUTPUT
AS
BEGIN
  SET NOCOUNT ON;
  SELECT @id = [id] from dbo.fileTypes where dirId = @fileType;
  -- if the procedure *also* needs to return this as a resultset:
  SELECT [id] = @id;
END
GO
然后使用:

declare @fileGuid uniqueidentifier;
exec dbo.usp_GetFileGuid @fileType = 'accounts', @id = @fileGuid OUTPUT;
print @fileGuid;

返回的值是int,因为它是执行的状态

向调用过程或批处理返回状态值以指示 成功或失败以及失败的原因

您正在寻找一个输出参数

输出

指示该参数是输出参数。使用 输出参数以将值返回给过程的调用者。 text、ntext和image参数不能用作输出参数, 除非该过程是CLR过程。输出参数可以是 游标占位符,除非该过程是CLR过程。A. 不能将表值数据类型指定为 程序


返回的值是int,因为它是执行的状态

向调用过程或批处理返回状态值以指示 成功或失败以及失败的原因

您正在寻找一个输出参数

输出

指示该参数是输出参数。使用 输出参数以将值返回给过程的调用者。 text、ntext和image参数不能用作输出参数, 除非该过程是CLR过程。输出参数可以是 游标占位符,除非该过程是CLR过程。A. 不能将表值数据类型指定为 程序


非常感谢。我相信这对你来说只是小菜一碟。我正在从编写简单的select语句过渡到编写过程:谢谢。我相信这对你来说只是小菜一碟。我正在从编写简单的select语句过渡到编写过程: