這裏很基本,因爲我試圖插入表中,但是在下面出現錯誤。請幫助使用uniqueidentifier轉換失敗
SET ANSI_WARNINGS OFF
INSERT INTO [P6_GrassleyCommitteeInc_20150223].[dbo].[std_Individual]
([ind_GUID]
,[ind_Prefix]
,[ind_FirstName]
,[ind_MiddleName]
,[ind_LastName]
,[ind_Suffix]
,[ind_ProfSuffix]
,[ind_Title]
,[ind_MailName]
,[ind_Salutation1]
,[ind_Salutation2]
,[ind_pty_GUID]
,[ind_eth_GUID]
,[ind_rac_GUID]
--,[ind_clo_GUID]
,[ind_occ_GUID]
,[ind_og1_GUID]
,[ind_og2_GUID]
,[ind_og3_GUID]
,[ind_Birthdate]
,[ind_Register]
,[ind_Gender]
,[ind_Marital]
,[ind_VoterId]
,[ind_SourceID]
,[ind_HashedID]
,[ind_Deleted]
,[ind_CreatedOn]
,[ind_CreatedBy]
--,[ind_UpdatedOn]
--,[ind_UpdatedBy]
--,[ind_DeletedOn]
--,[ind_DeletedBy]
,[ind_int_GUID]
,[ind_API_Id]
,[ind_Password]
--,[ind_tracking_GUID]
,[ind_Inactive]
--,[ind_GRPassword]
)
select
isnull(indguid,''), --,<ind_GUID, uniqueidentifier,>
'',-- ,<ind_Prefix, nvarchar(10),> --(i thought this field was [indiv. title] but it was not in this database
isnull(first_name,''), --,<ind_FirstName, nvarchar(30),>
'', --,<ind_MiddleName, nvarchar(30),>
isnull(last_name,''), --,<ind_LastName, nvarchar(30),>
'', --,<ind_Suffix, nvarchar(10),>
'', --,<ind_ProfSuffix, nvarchar(10),>
isnull(title,''), --,<ind_Title, nvarchar(100),>
isnull(mail_name,''), --,<ind_MailName, nvarchar(50),>
isnull(salutation,''), --,<ind_Salutation1, nvarchar(50),>
'', --,<ind_Salutation2, nvarchar(50),>
ptyguid, --,<ind_pty_GUID, uniqueidentifier,>
isnull(ethguid,''), --,<ind_eth_GUID, uniqueidentifier,>
racguid, --,<ind_rac_GUID, uniqueidentifier,>
--,<ind_clo_GUID, uniqueidentifier,>
occguid, -- ,<ind_occ_GUID, uniqueidentifier,>
og1guid, --,<ind_og1_GUID, uniqueidentifier,>
og2guid, --,<ind_og2_GUID, uniqueidentifier,>
og3guid, --,<ind_og3_GUID, uniqueidentifier,>
isnull(birthdate,''), -- <ind_Birthdate, datetime,>
isnull(register,''), -- <ind_Register, datetime,>
ISNULL(sex,''), --,<ind_Gender, nchar(1),>
'Z', --,<ind_Marital, nchar(1),>
ISNULL(VRNUMBER,''), --,<ind_VoterId, nvarchar(20),>
LTRIM(IDNUMBER), --,<ind_SourceID, nvarchar(50),>
'', --,<ind_HashedID, nvarchar(50),>
0, --,<ind_Deleted, bit,>
getdate(), --,<ind_CreatedOn, datetime,>
'00000000-0000-0000-0000-000000000000', --,<ind_CreatedBy, uniqueidentifier,>
--,<ind_UpdatedOn, datetime,>
--,<ind_UpdatedBy, uniqueidentifier,>
--,<ind_DeletedOn, datetime,>
--,<ind_DeletedBy, uniqueidentifier,>
intguid, --,<ind_int_GUID, uniqueidentifier,>
'', --,<ind_API_Id, nvarchar(10),>
'', --,<ind_Password, nvarchar(40),>
-- ,<ind_tracking_GUID, uniqueidentifier,>
case when recstatus = '3' then 1 else 0 end --,<ind_Inactive, bit,>
-- ,<ind_GRPassword, nvarchar(40),>)
From [P6_GrassleyCommitteeInc_20150223].[dbo].[i_Master] where enttype = 'ind'
GO
SET ANSI_WARNINGS ON
收到錯誤:
Msg 8169, Level 16, State 2, Line 2 Conversion failed when converting from a character string to uniqueidentifier.
來自[i_Master] .indguid的一個或多個值不是uniqueidentifier – sqluser 2015-02-24 03:33:55
由於您使用的是SQL 2012,因此您可以對試圖轉換爲guid的字段使用try_convert,並查看其位置結果爲空。 – Xedni 2015-02-24 04:02:04