整数与UniqueIdentifier不兼容

时间:2013-12-18 22:23:24

标签: sql sql-server function

这是我的代码:

USE [MRC]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[Lookup_APN_GUID] 
(
      -- Add the parameters for the function here
      @PN_Key int
)
RETURNS UNIQUEIDENTIFIER
AS
BEGIN
      -- Declare the return variable here
      DECLARE @PN_GUID UNIQUEIDENTIFIER

      SELECT @PN_GUID = PNID
      FROM PNEB
      WHERE PNID = (@PN_Key)

      RETURN @PN_GUID
END

我收到以下错误消息:

  

Msg 206,Level 16,State 2   过程Lookup_PN_GUID,操作数类型冲突:int与uniqueidentifier不兼容

我尝试在标量变量声明上将int切换为nvarchar。仍然收到错误消息。 uniqueidentifierint。我很茫然。

任何想法?

1 个答案:

答案 0 :(得分:0)

USE [MRC]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[Lookup_APN_GUID] 
(
      -- Add the parameters for the function here
      @PN_Key int
)
RETURNS UNIQUEIDENTIFIER
AS
BEGIN
      -- Declare the return variable here
      DECLARE @PN_GUID UNIQUEIDENTIFIER
      SELECT @PN_GUID = PNID
      FROM PNEB
      **WHERE APNID = (@PN_Key)**

      RETURN @PN_GUID
END