2016-04-12 5 views
1

Excelデータベースから直接MySQLデータベースに問い合わせるODBC接続を作成します。これは、元のMySQLデータベースとMicrosoft Queryからの接続の両方で完璧に機能するaprox 60 select文を使用した非常に複雑なクエリです。簡素化する他にexcel mysqlがすべてのselect文を読み取っていない

select 
    nom_client as Custname 
    ,case when locate('/',nom_voyageur) > 0 
     then substring(nom_voyageur,1,locate('/',nom_voyageur)-1) 
     else nom_voyageur end as Lastname 
    ,case when locate('/',nom_voyageur) > 0 
     then substring(nom_voyageur,locate('/',nom_voyageur) + 1, length(nom_voyageur)-locate('/',nom_voyageur)) 
     else '' end as Firstname 
    ,zone_stat_1 as Empcode 
    ,concat(substring(booker,locate(' ',booker) + 1, length(booker)-locate(' ',booker)),' ',substring(booker,1,locate(' ',booker)-1)) as Booker 
    ,zone_stat_3 as 'Euronext TAF Approver level 2' 
    ,'' as "Trip Reason" 
    ,prestation_name as Vendor 
    ,departure_date as Servicedate 
    ,'' as Savings 
    ,advance_purchase as Advpurchgroup 
    , tickets_number as Ticketcount 
    , '' as Triplength 
    ,'' as 'Class of Service' 
    ,case Activite when 1 then 'Rail' 
     when 2 then 'Hotel' 
     when 3 then 'Maritime' 
     when 4 then 'Fees/Regulations' 
     when 5 then 'Air' 
     when 6 then 'Frais' 
     when 7 then 'Visa/Shipments/Subscriptions/ESTA' end as Producttype 
    ,case when length(trajet_origine_destination) > length(replace(trajet_origine_destination,'/','')) 
     then substring(trajet_origine_destination,1,locate('/',trajet_origine_destination)-1) 
     else trajet_origine_destination end as 'Origin Cityname' 
    ,case when length(trajet_origine_destination) > length(replace(trajet_origine_destination,'/','')) 
     then substring(trajet_origine_destination,locate('/',trajet_origine_destination) + 1, length(trajet_origine_destination)-locate('/',trajet_origine_destination)) 
     else trajet_origine_destination end as 'Destination Cityname' 
    ,'Invoice' as Fop 
    ,'APInv' as 'Journal Name' 
    ,Invoice_date as 'Invoice Date' 
    ,'Vendor' as 'Account Type' 
    ,'' as LCOA 
    ,640139 as 'Main Account' 
    ,Zone_stat_2 as 'Cost Center' 
    ,'' as Project 
    ,'' as MarketSegment 
    ,'' as Custumer 
    ,'FAES000528' as Supplier 
    ,'' as Intercompany 
    ,'' as Product 
    ,'' as Dim9 
    ,'' as Dim10 
    ,'Ledger' as OffAccountType 
    ,'' as OffMainAccount 
    ,'' as OffsetLCOA 
    ,'' as OffCostCenter 
    ,'' as OffProject 
    ,'' as OffMarketSegment 
    ,'' as OffCustomer 
    ,'' as OffSupplier 
    ,'' as OffIntercompany 
    ,'' as OffProduct 
    ,'' as OffDim9 
    ,'' as OffDim10 
    ,concat('FCM-Invoice ',numero_facture,' - ',prestation_name,' - ',substring(nom_voyageur,1,locate('/',nom_voyageur)-1),' ',substring(nom_voyageur,locate('/',nom_voyageur) + 1, length(nom_voyageur)-locate('/',nom_voyageur))) as Description ## <-- THIS!!! 
    ,'EUR' as CurrencyCode 
    ,case when Montant_vente > 0 then Montant_vente else 0 end as AmountCurDebit 
    ,case when Montant_vente < 0 then Montant_vente*-1 else 0 end as AmountCurCredit 
    ,case when Montant_vente > 0 then Montant_vente else 0 end as FunctionalCUrDebit 
    ,case when Montant_vente < 0 then Montant_vente*-1 else 0 end as FunctionalCurCredit 
    ,'AP Posting' as PostingProfile 
    ,'Electronic' as PaymMode 
    ,'INMEDIATE' as Payment 
    ,concat(year(now()),'-',if(month(now())<10,concat('0',month(now())),month(now())),'-13') as Due ## <-- THIS!!! 
    ,'AP_DOM' as 'TaxGroup' 
    ,case activite when 6 then 'HIGH_S' else 'EXEMPT' end as TaxItemGroup 
    ,'' as DocumentNum 
    ,Invoice_date as DocumentDate 
    ,numero_facture as Invoice 
    ,'' as Prepayment 
    ,'' TaxCode 
    ,'' ExchRate 
    ,'No' as ReverseEntry 
    ,'' as ReverseDate 
    ,'FAES' as Company 
    ,'FAES' as OffsetCompany 
from extrait_sapeig_stat e 
where mot_dir_client = 'ETT' 
    and invoice_year = year(date_add(now(),Interval -1 month)) and invoice_month = month(date_add(now(),Interval -1 month)) 
    and activite != 11 
order by invoice_date, numero_facture; 

、これらは故障文

ある - 私はExcelシートに結果を公表する場合しかし、それは2つ(THIS !!!コメントの両方が## <を持っている)を除き、すべての列を示しています
',substring(nom_voyageur,locate('/',nom_voyageur) + 1, length(nom_voyageur)-locate('/',nom_voyageur))) as Description ## <-- THIS!!! 
,concat(year(now()),'-',if(month(now())<10,concat('0',month(now())),month(now())),'-13') as Due ## <-- THIS!!! 

私は彼らがなぜ失敗しているのか分かりません。私はすでに同じクエリ内に長い文があり、関数concat()もすでに動作しています。 3つ以上インデントされた関数を持つステートメントに問題があると仮定していますが、わかりません。あなたのいずれかが、これが失敗する理由の任意のアイデアを持っている場合、それはMicrosoft Queryで私にExcelシートにdesappeared

Microsoft Query

説明列をたくさん

正しい結果を助ける

Excel Sheet

+0

を持っている私は私が明示的に変換しなければならない問題!、連結関数内の文字列にすべての値を見つけ –

+0

!、問題を発見しました。 今、私はこれを持っています SELECT concat( 'FCM-Invoice'、置き換えます(フォーマット番号nume​​ro_facture、0)、 '、'、 '')、 ' - '、prestation_name、 ' - '、部分文字列(nom_voyageur、1、説明として、部分文字列(nom_voyageur、locate( '/'、nom_voyageur)+ 1、長さ(nom_voyageur)-locate( '/'、nom_voyageur)))を指定します( date_format (now()、 '%Y-%m-13')をextrait_sapeig_stat eから としています –

答えて

0

問題が見つかりました!私はすべての値をconcat関数内の文字列に明示的に変換する必要があります。

今、私はこの

SELECT concat('FCM-Invoice ',replace(format(numero_facture,0),',',''),' - ',prestation_name,' - ',substring(nom_voyageur,1,locate('/',nom_voyageur)-1),' ',substring(nom_voyageur,locate('/',nom_voyageur) + 1, length(nom_voyageur)-locate('/',nom_voyageur))) as description, 
date_format(now(),'%Y-%m-13') as due 
from extrait_sapeig_stat e 
0

なぜそれをMSAccessに変換してから、conver t MSAccess to MySQL