現在、あるテーブルからデータを取り出し、いくつかの制約に基づいて別のテーブルにデータを挿入しようとしています。 私は、スクリプトを実行すると残念ながら、私は次のエラーを取得:データ型nvarcharをfloatに変換するSQL INSERT INTO SELECTエラー
error converting data type nvarchar to float
をし、私はこの問題を解決するために、クエリを変更することができますかわからないんです。ソーステーブルと宛先テーブルの両方にはすべてのフィールドがnvarchar(255)
となっています。私は何をすべきかよく分かりません。
次のようにSQLクエリは次のとおりです。
Insert into Database.dbo.ML_Records ([AccountNumber]
,[House Number]
,[Street]
,[City]
,[Postalcode]
,[County]
,[Phone]
,[Country]
,[Account Type]
,[Nr_of_Dependents]
,[FirstName]
,[LasName]
,[Title]
,[JobTitle]
,[Email]
,[LeadType]
,[LeadSource]
,[LeadOrigin]
,[CampaignCode]
,[Contact_Preference]
,[Product_Interest]
,[NewServicesForCustomer]
,[Lead_Description])
Select [Account Number] as [AccountNumber]
, NULL as [House Number]
, [Address Line 1] + ' ' + [Address Line 2] as [Street]
, Town as [City]
, Postcode as [Postalcode]
, County as [County]
, case when [Telephone] is null then [Mobile] else [Telephone] end as [Phone]
, NULL as [Country]
, case when [Account Type 2] is not null and [Identical Accounts] = 'No' then [Account Type 2] else [Account Type 1] end as [Account Type]
, [Number of Dependents] as [Nr_of_Employees_Company_Modelled]
, [Forename] as [FirstName]
, [Surname] as [LastName]
, [Title] as [Title]
, [Job Title] as [JobTitle]
, case when [Email] is null then [Site Email] else [Email] end as [Email]
, NULL as [LeadType]
, NULL as [LeadSource]
, NULL as [LeadOrigin]
, case when ((([Email] is not NULL or [Site Email] is not null) and [Do NOT EMAIL] <> 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 0 then 'A-B2F-CL-TM/EM-M2-CAT0-GL'
when ((([Email] is not NULL or [Site Email] is not null) and [Do NOT EMAIL] <> 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 1 then 'A-B2F-CL-TM/EM-M2-CAT1-GL'
when ((([Email] is not NULL or [Site Email] is not null) and [Do NOT EMAIL] <> 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 2 then 'A-B2F-CL-TM/EM-M2-CAT2-GL'
when ((([Email] is not NULL or [Site Email] is not NULL) AND [Do NOT EMAIL] <> 'Y') and (([Telephone] is NULL AND [Mobile] is NULL) OR [DO NOT TELEPHONE] = 'Y')) and [CAT Status] = 0 then 'A-B2F-CL-EM-M2-CAT0-GL'
when ((([Email] is not NULL or [Site Email] is not NULL) AND [Do NOT EMAIL] <> 'Y') and (([Telephone] is NULL AND [Mobile] is NULL) OR [DO NOT TELEPHONE] = 'Y')) and [CAT Status] = 1 then 'A-B2F-CL-EM-M2-CAT1-GL'
when ((([Email] is not NULL or [Site Email] is not NULL) AND [Do NOT EMAIL] <> 'Y') and (([Telephone] is NULL AND [Mobile] is NULL) OR [DO NOT TELEPHONE] = 'Y')) and [CAT Status] = 2 then 'A-B2F-CL-EM-M2-CAT2-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 0 then 'A-B2F-CL-TM-M2-CAT0-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 1 then 'A-B2F-CL-TM-M2-CAT1-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) and [CAT Status] = 2 then 'A-B2F-CL-TM-M2-CAT2-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and ((([Telephone] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')) AND (([Mobile] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')))) and [CAT Status] = 0 then 'A-B2F-CL-DM-M2-CAT0-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and ((([Telephone] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')) AND (([Mobile] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')))) and [CAT Status] = 1 then 'A-B2F-CL-DM-M2-CAT1-GL'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and ((([Telephone] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')) AND (([Mobile] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')))) and [CAT Status] = 2 then 'A-B2F-CL-DM-M2-CAT2-GL' end as [CampaignCode]
, case when ((([Email] is not NULL or [Site Email] is not null) and [Do NOT EMAIL] <> 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) then 'EM/TM'
when ((([Email] is not NULL or [Site Email] is not NULL) AND [Do NOT EMAIL] <> 'Y') and (([Telephone] is NULL AND [Mobile] is NULL) OR [DO NOT TELEPHONE] = 'Y')) then 'EM'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and (([Telephone] is not null or [Mobile] is not null) and [DO NOT TELEPHONE] <> 'Y' and [Records on TPS] is NULL and [Records on CTPS] is NULL)) then 'TM'
when ((([Email] is NULL and [Site Email] is null) or [Do NOT EMAIL] = 'Y') and ((([Telephone] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')) AND (([Mobile] is NULL OR [DO NOT TELEPHONE] = 'Y') OR ([Records on TPS] = '1' or [Records on CTPS] = '1')))) then 'DM' end as [Contact_Preference]
, NULL as [Product_Interest]
, NULL as [NewServicesForCustomer]
, [CAT Status] +',' + [Competitor available 1] + ',' + [Competitor available 2] + ',' + [Competitor available 3] + ',' + [Competitor available 4] + ',' + [Competitor available 5] + ',' + [Competitor available 6] + ',' + [Competitor available 7] + ',' + [Competitor available 8] + ',' + [Competitor available 9] + ',' + [Last year accounts paid?] as [Description]
from ML_Pre_Test_Master
where [Commercial premise (yes/no)] <> 'Yes - Closed'
あなたは貸すことができ、任意のヘルプは大幅にそれは[Descripion]に連接されてい... [猫ステータス]で
NVARCHARフィールドをFLOATに挿入しようとしています。 SELECTをチェックしてください。そうであれば、フィールドをFLOATに変換してください。 – galloleonardo
しかし、ソーステーブルと最終テーブルの両方にはNVARCHARフィールドしかありません。どこでもFLOATを指定することはありませんので、何をすべきか分かりません。 フィールドを変換する場合は、どこで変換する必要がありますか?元のテーブルでは?または、クエリのどこかにcast()関数を置くことはできますか? – MichaelL
ソースとデスティネーションのすべての列がvarchar(255)ですが、ケースステートメントでは、たとえばテストしています。 '[CAT Status] = 0'(1,2など)これは数値定数なので、[CAT Status]を変換して比較しようとします。 – SQLBadPanda