0

次のクエリを改善するために取り組んでいます。

Set rs = CurrentDb.OpenRecordset("SELECT CONSG.custpartno AS Assembly, SOM.sono AS SO, SOD.line_no AS Rel, PLD.shippedqty AS Qty, INV.descript AS Description, " & _
  "SHIPADDR.shipto AS ShipToCompany, SHIPADDR.address1 AS ShipToAddress, SHIPADDR.address2 AS ShipToAddress2, SHIPADDR.city AS ShipToCity, SHIPADDR.state AS ShipToState, SHIPADDR.zip AS ShipToZip,  " & _
  "BILLADDR.shipto AS BillToCompany, BILLADDR.address1 AS BillToAddress, BILLADDR.address2 AS BillToAddress2, BILLADDR.city AS BillToCity, BILLADDR.state AS BillToState, BILLADDR.zip AS BillToZip " & _
  "FROM inventor AS CONSG INNER JOIN ((((((plmain AS PLM INNER JOIN pldetail AS PLD ON PLM.packlistno = PLD.packlistno) INNER JOIN sodetail AS SOD ON PLD.uniqueln = SOD.uniqueln) INNER JOIN inventor AS INV ON SOD.uniq_key = INV.uniq_key) INNER JOIN somain AS SOM ON PLM.sono = SOM.sono) INNER JOIN shipbill AS SHIPADDR ON PLM.linkadd = SHIPADDR.linkadd) INNER JOIN shipbill AS BILLADDR ON PLM.blinkadd = BILLADDR.linkadd) ON CONSG.int_uniq = INV.uniq_key  " & _
  "WHERE Val(PLM.packlistno) = " & cboPL.value, dbOpenDynaset)

住所を構成する個々のフィールドすべてではなく、請求先住所用に 1 つのフィールドと出荷先住所用に 1 つのフィールドを用意したいと考えています。次の形式でお願いします。

Company Name
110 Company Street Address
Address second line 
City, State Zip

一部の住所では、2 行目の住所がありません。ですから、その行は完全にスキップしたいと思います。また、何らかの理由で、各フィールドの後に必要のない余分なスペースがあります。

これを達成する方法を知っている人はいますか?

4

1 に答える 1

1
Set rs = CurrentDb.OpenRecordset("SELECT CONSG.custpartno AS Assembly, SOM.sono AS SO, SOD.line_no AS Rel, PLD.shippedqty AS Qty, INV.descript AS Description, " & _
  "Trim(SHIPADDR.shipto) & Chr(13) & Chr(10) & Trim(SHIPADDR.address1) & Chr(13) & Chr(10) & IIf(Len(Trim(SHIPADDR.address2) & '')<>0,Trim(SHIPADDR.address2) & Chr(13) & Chr(10),'') & Trim(SHIPADDR.city) & ', ' & Trim(SHIPADDR.state) & ' ' & Trim(SHIPADDR.zip) AS ShipTo,   " & _
  "Trim(BILLADDR.shipto) & Chr(13) & Chr(10) & Trim(BILLADDR.address1) & Chr(13) & Chr(10) & IIf(Len(Trim(BILLADDR.address2) & '')<>0,Trim(BILLADDR.address2) & Chr(13) & Chr(10),'') & Trim(BILLADDR.city) & ', ' & Trim(BILLADDR.state) & ' ' & Trim(BILLADDR.zip) AS BillTo " & _
  "FROM inventor AS CONSG INNER JOIN ((((((plmain AS PLM INNER JOIN pldetail AS PLD ON PLM.packlistno = PLD.packlistno) INNER JOIN sodetail AS SOD ON PLD.uniqueln = SOD.uniqueln) INNER JOIN inventor AS INV ON SOD.uniq_key = INV.uniq_key) INNER JOIN somain AS SOM ON PLM.sono = SOM.sono) INNER JOIN shipbill AS SHIPADDR ON PLM.linkadd = SHIPADDR.linkadd) INNER JOIN shipbill AS BILLADDR ON PLM.blinkadd = BILLADDR.linkadd) ON CONSG.int_uniq = INV.uniq_key  " & _
  "WHERE Val(PLM.packlistno) = " & cboPL.value, dbOpenDynaset)

上記のChr(13)= 改行と = 改行Chr(10)Trim()フィールドの先頭と末尾のスペースを削除するために使用します。次に、空白の住所行 2 に余分な行を追加しないようにするには、長さを確認し、0 より大きい場合にのみ住所に追加します。

于 2013-10-02T17:08:11.827 に答える