简体   繁体   English

操作数类型冲突:int与sqlsever 2012中的uniqueidentifier不兼容

[英]Operand type clash: int is incompatible with uniqueidentifier in sqlsever 2012

when i am trying to execute this storted proc am facing an error int is incompatiable with uniqueidentifier.my userid coloumn is bigint 当我尝试执行此存储过程时,遇到一个错误int与uniqueidentifier不兼容。我的userid coloumn是bigint

USE [iFlipOut_Dev] GO / * USE [iFlipOut_Dev]转到/ * Object: StoredProcedure [dbo].[SaveRegistration] Script Date: 4/14/2013 3:29:40 PM 对象:StoredProcedure [dbo]。[SaveRegistration]脚本日期:2013/4/14下午3:29:40 * / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO * / SET ANSI_NULLS ON GO设置QUOTED_IDENTIFIER ON GO

ALTER PROCEDURE [dbo].[SaveRegistration]  
(
   @p_UserId int,
   @p_FirstName nvarchar(150),
   @p_LastName nvarchar(50),
   @p_Gender nvarchar(10),
   @p_Email nvarchar(150),
   @p_Mobile nvarchar(12),
   @p_Phone nvarchar(12),
   @p_DateOfBirth nvarchar(50),
   @p_Address nvarchar(250),
   @p_ZipCode nvarchar(10),
   @p_City nvarchar(100),
   @p_StateId smallint,
   @p_LoginId int,
   @p_UserStatusId smallint,
   @p_LanguageId smallint,
   @p_ModifiedBy bigint,
   @p_CountryId smallint,
   @p_UserImage nvarchar(20),
   @p_publicRegistrationId nvarchar(50),
   @p_TimeZone_Id smallint

   )
AS 
   BEGIN

      SET  NOCOUNT  ON


      IF 
         CASE 
            WHEN EXISTS 
               (
                  SELECT 
                     UD.UserId, 
                     UD.FirstName, 
                     UD.LastName, 
                     UD.Gender, 
                     UD.email, 
                     UD.Mobile, 
                     UD.phone, 
                     UD.DateOfBirth, 
                     UD.Address, 
                     UD.ZipCode, 
                     UD.City, 
                     UD.StateId, 
                     UD.LoginId, 
                     UD.UserStatusId, 
                     UD.LanguageId, 
                     UD.ModifiedBy, 
                     UD.ModifiedDate, 
                     UD.CountryId, 
                     UD.UserImage, 
                     UD.PublicRegistrationId, 
                     UD.TimeZone_Id,
                     UD.IsActivated
                  FROM dbo.UserDetails as UD
                  WHERE UD.UserId = @p_UserId
               ) THEN 1
            ELSE 0
         END <> 0
         /*
         *  Added UserId Coloumn to be inserted in the table
         */

         UPDATE dbo.UserDetails
            SET 
               FirstName = @p_FirstName, 
               LastName = @p_LastName, 
               Gender = @p_Gender, 
               Email = @p_Email, 
               Mobile = @p_Mobile, 
               Phone = @p_Phone, 
               DateOfBirth = @p_DateOfBirth, 
               Address = @p_Address, 
               ZipCode = @p_ZipCode, 
               City = @p_City, 
               StateId = @p_StateId, 
               LoginId = @p_LoginId, 
               UserStatusId = @p_UserStatusId, 
               LanguageId = @p_LanguageId, 
               ModifiedBy = @p_ModifiedBy, 
               ModifiedDate = isnull(getdate(), getdate()), 
               CountryId = @p_CountryId, 
               UserImage = @p_UserImage, 
               PublicRegistrationId=@p_publicregistrationId,
               TimeZone_Id = @p_TimeZone_Id

         WHERE UserDetails.UserId = @p_UserId
      ELSE 
         BEGIN

            /*
            *  added userid coloumn in the insert statement
            */

            INSERT dbo.UserDetails(
               dbo.UserDetails.FirstName, 
               dbo.UserDetails.LastName, 
               dbo.UserDetails.Gender, 
               dbo.UserDetails.email, 
               dbo.UserDetails.Mobile, 
               dbo.UserDetails.Phone, 
               dbo.UserDetails.DateOfBirth, 
               dbo.UserDetails.Address, 
               dbo.UserDetails.ZipCode, 
               dbo.UserDetails.City, 
               dbo.UserDetails.StateId, 
               dbo.UserDetails.LoginId, 
               dbo.UserDetails.UserStatusId, 
               dbo.UserDetails.LanguageId, 
               dbo.UserDetails.ModifiedBy, 
               dbo.UserDetails.ModifiedDate, 
               dbo.UserDetails.CountryId, 
               dbo.UserDetails.UserImage, 
               dbo.UserDetails.PublicRegistrationId, 
               dbo.UserDetails.TimeZone_Id)


               VALUES (
                  @p_FirstName, 
                  @p_LastName, 
                  @p_Gender, 
                  @p_Email, 
                  @p_Mobile, 
                  @p_Phone, 
                  @p_DateOfBirth, 
                  @p_Address, 
                  @p_ZipCode, 
                  @p_City, 
                  @p_StateId, 
                  @p_LoginId, 
                  @p_UserStatusId, 
                  @p_LanguageId, 
                  @p_ModifiedBy, 
                  isnull(getdate(), getdate()), 
                  @p_CountryId, 
                  @p_UserImage, 
                  newid(), 
                  @p_TimeZone_Id)





            SET @p_UserId = scope_identity()

         END

      SELECT @p_UserId AS UserId

   END

Yes. 是。 Int and GUID data-types are not compatible. Int和GUID数据类型不兼容。 Can you specify, where exactly error occurs. 您能否指定确切的错误发生位置。

I also little rewrote your sp - 我也很少重写您的sp-

ALTER PROCEDURE [dbo].[SaveRegistration]  
(
   @p_UserId int,
   @p_FirstName nvarchar(150),
   @p_LastName nvarchar(50),
   @p_Gender nvarchar(10),
   @p_Email nvarchar(150),
   @p_Mobile nvarchar(12),
   @p_Phone nvarchar(12),
   @p_DateOfBirth nvarchar(50),
   @p_Address nvarchar(250),
   @p_ZipCode nvarchar(10),
   @p_City nvarchar(100),
   @p_StateId smallint,
   @p_LoginId int,
   @p_UserStatusId smallint,
   @p_LanguageId smallint,
   @p_ModifiedBy bigint,
   @p_CountryId smallint,
   @p_UserImage nvarchar(20),
   @p_publicRegistrationId nvarchar(50),
   @p_TimeZone_Id smallint

   )
AS BEGIN

      SET  NOCOUNT  ON

      IF EXISTS (
            SELECT 1
            FROM dbo.UserDetails UD
            WHERE UD.UserId = @p_UserId
        ) BEGIN


         UPDATE dbo.UserDetails
            SET 
               FirstName = @p_FirstName, 
               LastName = @p_LastName, 
               Gender = @p_Gender, 
               Email = @p_Email, 
               Mobile = @p_Mobile, 
               Phone = @p_Phone, 
               DateOfBirth = @p_DateOfBirth, 
               Address = @p_Address, 
               ZipCode = @p_ZipCode, 
               City = @p_City, 
               StateId = @p_StateId, 
               LoginId = @p_LoginId, 
               UserStatusId = @p_UserStatusId, 
               LanguageId = @p_LanguageId, 
               ModifiedBy = @p_ModifiedBy, 
               ModifiedDate = getdate(), 
               CountryId = @p_CountryId, 
               UserImage = @p_UserImage, 
               PublicRegistrationId=@p_publicregistrationId,
               TimeZone_Id = @p_TimeZone_Id
         WHERE UserDetails.UserId = @p_UserId

      END
      ELSE BEGIN

            INSERT dbo.UserDetails(
               FirstName, 
               LastName, 
               Gender, 
               email, 
               Mobile, 
               Phone, 
               DateOfBirth, 
               Address, 
               ZipCode, 
               City, 
               StateId, 
               LoginId, 
               UserStatusId, 
               LanguageId, 
               ModifiedBy, 
               ModifiedDate, 
               CountryId, 
               UserImage, 
               PublicRegistrationId, 
               TimeZone_Id)
            SELECT
                  @p_FirstName, 
                  @p_LastName, 
                  @p_Gender, 
                  @p_Email, 
                  @p_Mobile, 
                  @p_Phone, 
                  @p_DateOfBirth, 
                  @p_Address, 
                  @p_ZipCode, 
                  @p_City, 
                  @p_StateId, 
                  @p_LoginId, 
                  @p_UserStatusId, 
                  @p_LanguageId, 
                  @p_ModifiedBy, 
                  getdate(), 
                  @p_CountryId, 
                  @p_UserImage, 
                  newid(), 
                  @p_TimeZone_Id

            SELECT @p_UserId = scope_identity()

         END

      SELECT @p_UserId AS UserId

   END

Cleanup means that: 清理意味着:

IF 
         CASE 
            WHEN EXISTS 
               (
                  SELECT 
                     UD.UserId, 
                     UD.FirstName, 
                     UD.LastName, 
                     UD.Gender, 
                     UD.email, 
                     UD.Mobile, 
                     UD.phone, 
                     UD.DateOfBirth, 
                     UD.Address, 
                     UD.ZipCode, 
                     UD.City, 
                     UD.StateId, 
                     UD.LoginId, 
                     UD.UserStatusId, 
                     UD.LanguageId, 
                     UD.ModifiedBy, 
                     UD.ModifiedDate, 
                     UD.CountryId, 
                     UD.UserImage, 
                     UD.PublicRegistrationId, 
                     UD.TimeZone_Id,
                     UD.IsActivated
                  FROM dbo.UserDetails as UD
                  WHERE UD.UserId = @p_UserId
               ) THEN 1
            ELSE 0
         END <> 0

Can optimize to: 可以优化为:

 IF EXISTS (
            SELECT 1
            FROM dbo.UserDetails UD
            WHERE UD.UserId = @p_UserId
        ) BEGIN

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

相关问题 操作数类型冲突:uniqueidentifier与查询中的int不兼容 - Operand type clash: uniqueidentifier is incompatible with int in query 操作数类型冲突:uniqueidentifier与int不兼容 - Operand type clash: uniqueidentifier is incompatible with int SQL Server:返回的UniqueIdentifier,操作数类型冲突:uniqueidentifier与int不兼容 - SQL Server: Returning UniqueIdentifier, Operand type clash: uniqueidentifier is incompatible with int SQL Server-与工会的错误“操作数类型冲突uniqueidentifier与int不兼容” - SQL Server - error 'operand type clash uniqueidentifier is incompatible with int' with Union SQL-Server - 操作数类型冲突:uniqueidentifier与int不兼容 - SQL-Server - Operand type clash: uniqueidentifier is incompatible with int 操作数类型冲突:文本与uniqueidentifier不兼容 - Operand type clash: text is incompatible with uniqueidentifier SQL Server 2012(触发器)操作数类型冲突:int与日期不兼容 - SQL Server 2012 (triggers) Operand type clash: int is incompatible with date 存储过程-操作数类型冲突:smallint与uniqueidentifier不兼容 - Stored procedure - Operand type clash: smallint is incompatible with uniqueidentifier 操作数类型冲突:date与dateadd中的int不兼容 - Operand type clash: date is incompatible with int in dateadd 操作数类型冲突:时间与int不兼容 - Operand type clash: time is incompatible with int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM