2017-12-22 12 views
0

すべてが1行にある購買発注依頼のデータがあります。これらを財務システムにインポートしてPOを生成するには、ユニオンで各明細のデータを選択します。私はビューを作成し、それは素晴らしい仕事をしています。昨日、1つのPOの広告申込情報をすべて引き出していないものがありました。それを研究するにあたっては、最初の5つの広告申込情報のコードをこのリクエストのアイテム数とし、コードを実行しました。それはすべてを引っ張ってこなかった。だから私はそれが引っ張っていなかったとすべてが現れたのを見ることができるように各広告申込情報に静的な番号を追加しました。なぜなら私はこれ以外のすべてを投稿することができない長さの 作品SQLクエリがすべてのレコードをプルしていない

SELECT '5' AS lineitem,`f`.`DWDOCID` AS `a` 
, DATE_FORMAT(CURDATE(), '%m/%d/%y') AS `B` 
, `f`.`FIELD_9` AS `C` 
, `f`.`VENDORCODE` AS `d` 
, `f`.`EMPLOYEENUMBER` AS `e` 
, `f`.`REMARKS` AS `f` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Family Enrichment Network' 
    END) AS `shiptoname` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '21 South Broad Street' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '6678 County Rd 32' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN '24 Cherry Street' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '150 Moeller St.' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN '35 Felters Rd.' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '287 Prospect St.' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '30 College St.' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '29 Fayette St.' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '117 Whig St.' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN '1277 Taylor Rd.' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN '12 Cooper St.' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN '1201 Union Center Maine Highway' 
    END) AS `address` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'PO Box 997' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Building 16' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Linnaeus West Elementary School, Classroom 15' 
    END) AS `address2` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Norwich, NY 13815' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Norwich, NY 13815' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Johnson City, NY 13790-0997' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Binghamton, NY 13904' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Binghamton, NY 13903' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Binghamton, NY 13905' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Binghamton, NY 13905' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Binghamton, NY 13901' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Newark Valley, NY 13811' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Owego, NY 13827' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Waverly, NY 14892' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Endicott, NY 13760' 
    END) AS `citystatezip` 
, 'Best Way' AS `BestWay` 
, DATE_FORMAT(`f`.`DATENEEDED`, '%m/%d/%y') AS `date_format(f.DATENEEDED,'%m/%d/%y')` 
, (`f`.`Q5` * 0.01) AS `q5` 
, `f`.`DES5` AS `DES5` 
, (`f`.`UPRICE5`/100) AS `f.UPRICE5/100` 
, '0' AS `0` 
, 0 AS `f.shipping/100` 
, `f`.`DWDOCID` AS `DWDOCID` 
, '0' AS `My_exp_1_0` 
, '0' AS `My_exp_2_0` 
, '0' AS `My_exp_3_0` 
, `f`.`GLCODE5` AS `GLCODE` 
, `f`.`ELEMENT5` AS `ELEMENT` 
, ((`f`.`UPRICE5`/100) * (`f`.`Q5` * 0.01)) AS `amount` 
, 'm:\\nbush.jpg' AS `Y` 
, DATE_FORMAT(`f`.`APPROVALDATE`, '%m/%d/%y') AS `Approvaldate` 
, 'm:\\blank.jpg' AS `AA` 
, REPLACE(LEFT(`f`.`VENDOR`, 20), '#N/A', '') AS `replace(left(``f``.``vendor``,20),'#N/A','')` 
    FROM `dwdata`.`purchase_orders` `f` 
    WHERE ((`f`.`DOCUMENT_TYPE` = 'REQUISITION FOR PURCHASE ORDER') 
AND (`f`.`FIELD_9` = 'Executive Director Approved') 
    AND (`f`.`EXECUTIVEDIRECTORAPPROVED` = 'Approved') 
AND (`f`.`FISCALOFFICERAPPROVED` = 'Approved') 
AND (`f`.`PROGRAMDIRECTORAPPROVED` = 'Approved') 

AND (`f`.`Q5` IS NOT NULL)) 

このんではない

SELECT `f`.`DWDOCID` AS `a` 
, DATE_FORMAT(CURDATE(), '%m/%d/%y') AS `B` 
, `f`.`FIELD_9` AS `C` 
, `f`.`VENDORCODE` AS `d` 
, `f`.`EMPLOYEENUMBER` AS `e` 
, `f`.`REMARKS` AS `f` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Family Enrichment Network' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Family Enrichment Network' 
    END) AS `shiptoname` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '21 South Broad Street' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '6678 County Rd 32' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN '24 Cherry Street' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '150 Moeller St.' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN '35 Felters Rd.' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '287 Prospect St.' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '30 College St.' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '29 Fayette St.' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '117 Whig St.' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN '1277 Taylor Rd.' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN '12 Cooper St.' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN '1201 Union Center Maine Highway' 
    END) AS `address` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'PO Box 997' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Building 16' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN '' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Linnaeus West Elementary School, Classroom 15' 
    END) AS `address2` 
, (CASE 
     WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Norwich, NY 13815' 
     WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Norwich, NY 13815' 
     WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Johnson City, NY 13790-0997' 
     WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Binghamton, NY 13904' 
     WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Binghamton, NY 13903' 
     WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Binghamton, NY 13905' 
     WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Binghamton, NY 13905' 
     WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Binghamton, NY 13901' 
     WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Newark Valley, NY 13811' 
     WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Owego, NY 13827' 
     WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Waverly, NY 14892' 
     WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Endicott, NY 13760' 
    END) AS `citystatezip` 
, 'Best Way' AS `BestWay` 
, DATE_FORMAT(`f`.`DATENEEDED`, '%m/%d/%y') AS `date_format(f.DATENEEDED,'%m/%d/%y')` 
, (`f`.`Q5` * 0.01) AS `q5` 
, `f`.`DES5` AS `DES5` 
, (`f`.`UPRICE5`/100) AS `f.UPRICE5/100` 
, '0' AS `0` 
, 0 AS `f.shipping/100` 
, `f`.`DWDOCID` AS `DWDOCID` 
, '0' AS `My_exp_1_0` 
, '0' AS `My_exp_2_0` 
, '0' AS `My_exp_3_0` 
, `f`.`GLCODE5` AS `GLCODE` 
, `f`.`ELEMENT5` AS `ELEMENT` 
, ((`f`.`UPRICE5`/100) * (`f`.`Q5` * 0.01)) AS `amount` 
, 'm:\\nbush.jpg' AS `Y` 
, DATE_FORMAT(`f`.`APPROVALDATE`, '%m/%d/%y') AS `Approvaldate` 
, 'm:\\blank.jpg' AS `AA` 
, REPLACE(LEFT(`f`.`VENDOR`, 20), '#N/A', '') AS `replace(left(``f``.``vendor``,20),'#N/A','')` 
    FROM `dwdata`.`purchase_orders` `f` 
    WHERE ((`f`.`DOCUMENT_TYPE` = 'REQUISITION FOR PURCHASE ORDER') 
AND (`f`.`FIELD_9` = 'Executive Director Approved') 
    AND (`f`.`EXECUTIVEDIRECTORAPPROVED` = 'Approved') 
AND (`f`.`FISCALOFFICERAPPROVED` = 'Approved') 
AND (`f`.`PROGRAMDIRECTORAPPROVED` = 'Approved') 
AND (`f`.`Q5` IS NOT NULL)) 

任意のアイデア理由は?広告申込情報以外はまったく同じコードです。

+0

これらの2つのステートメントは、 '' 5 'AS lineitem'を除いて同一です。別のレコード数を取得するように?あなたはこのSQL文のコードをすべて投稿していないと言いますが、あなたがここには含まれていないと思われる問題があると思われます。単にselect文節に 'lineitem'定数を追加するだけでは、あなたが投稿したSQLがあれば。ユニオンの前に各セクションの – JNevill

+0

を追加して、各レコードを強制的に一意にするようにしました。それが問題を解決しました。 – btg

答えて

0

私はそれを理解しました。私は、組合が重複した記録を検索しないことに気付かなかった。 POを記入した人が普通の人がしたことをして、1つの広告申込情報に2を、別の広告申込情報に3を、ちょうど2つしかない場合に1の数量を持つ5つの広告申込情報それは問題ではないでしょう。

関連する問題