简体   繁体   中英

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

USE [iFlipOut_Dev] GO / * Object: StoredProcedure [dbo].[SaveRegistration] Script Date: 4/14/2013 3:29:40 PM * / SET ANSI_NULLS ON GO SET 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. Can you specify, where exactly error occurs.

I also little rewrote your 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM