2013-04-15 64 views
1

當我試圖執行此storted PROC現在面臨的誤差int是incompatiable與uniqueidentifier.my的userid coloumn是BIGINT操作數類型衝突:int是與唯一標識符SQLSEVER不相容2012

USE [iFlipOut_Dev] GO /* 對象:StoredProcedure的[DBO] [SaveRegistration]腳本日期:2013年4月14日下午3時29分四十秒 */ 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, 
       [email protected]_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 
+1

一些你/存儲prcoedure筆者認爲是一個'int'實際上是一個'uniqueidentifier'。沒有看到您的調用代碼和/或您的模式,我們無法進一步協助。但是,我可以指出你的'EXISTS()'代碼似乎比它需要的更復雜。 ('IF CASE WHEN EXISTS()THEN 1 ELSE 0 END <> 0'可能就是'IF EXISTS()',並且不需要在那裏有一個列列表 - 這是SELECT *通常更合適 –

回答

1

是的。 Int和GUID數據類型不兼容。你能指定發生錯誤的地方嗎?

我也有點重寫了你的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, 
       [email protected]_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 

清理是指:

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 

可以優化到:

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

再次出現同樣的錯誤 – krish

+0

你能指定,哪裏發生了錯誤?或者爲表dbo添加模式描述dbo.UserDetails – Devart

+0

這並沒有真正回答這個問題 - 它只是做了一些樣式清理。不應該是一個答案。 –

相關問題