私はわずか5時間か6時間のSQL初心者です。私は速く勉強しています。"3つのテーブルを結合しようとすると、マルチパート識別子 'xxx'をバインドできませんでした。
最終的には、製品ラインごとにクライアントのアドレスを選択しようとしています。最初のテーブル(arinvch)には請求書が含まれているため、クライアントのアドレスが含まれています。 2番目のテーブル(aritrsh)にはテーブル1の請求書の個別明細が含まれ、3番目のテーブル(icitemh)には明細の製品明細が含まれます。
最初にサブクエリでテーブル2と3を結合しようとしましたが、最初に製品ラインを抽出し、最初のテーブルと結合して製品ラインごとに顧客アドレスを取得しました。簡単に言えば
、これは私が何をしようとしたものです:
SELECT
table1.addressinfo
FROM
table1
INNER JOIN
(SELECT * FROM
table2 INNER JOIN table3
ON table2.itemnumber = table3.itemnumber
WHERE table3.type = 'CRM') joinedtable
ON
table1.customernumber = joinedtable.customernumber;
正確なコード:
SELECT
arinvch.ccustno AS [Customer #],
arinvch.dinvoice AS [Invoice Date],
arinvch.cbcompany AS [Bill to Company],
arinvch.cbaddr1 AS [Bill to Address 1],
arinvch.cbaddr2 AS [Bill to Address 2],
arinvch.cbcity AS [Bill to City],
arinvch.cbstate AS [Bill to State],
arinvch.cbzip AS [Bill to Zip Code],
arinvch.cbcountry AS [Bill to Country],
arinvch.cbphone AS [Bill to Phone],
arinvch.cscompany AS [Ship To Company],
arinvch.csaddr1 AS [Ship To Address 1],
arinvch.csaddr2 AS [Ship To Address 2],
arinvch.cscity AS [Ship To City],
arinvch.csstate AS [Ship To State],
arinvch.cszip AS [Ship To Zip Code],
arinvch.cscountry AS [Ship To Country],
arinvch.csphone AS [Ship To Phone],
arinvch.cscontact AS [Ship To Contact],
aritrsh.cinvno AS [Invoice #],
aritrsh.citemno AS [Item Number],
icitemh.citemno AS [Item #]
FROM
arinvch
INNER JOIN
(SELECT
aritrsh.clineitem
FROM
aritrsh
INNER JOIN
icitemh
ON
aritrsh.citemno = icitemh.citemno
WHERE icitemh.ctype = 'CRM')table2
ON
arinvch.ccustno = aritrsh.ccustno;
これは(FlySpeed SQLで)次のエラーメッセージを返します。
[ FireDAC] [Phys] [ODBC] [Microsoft] [ODBC SQL Server Driver] [SQL Server] マルチパート識別子 "aritrsh.ccustno"はバインドできませんでした。
ありがとうございます! (また、副目標として、私はそれらが素晴らしいであろう請求書からそれらを引き出すときに私が繰り返しないアドレスを得ることができる方法を説明することができます。)私は多くの場所でSELECT DISTINCTを取り入れようとしましたが、 (私はtable1.customernumberがはっきりとWHERE DISTINCTものではありませんようにしたいと)ソリューションを仕事にする。)
ここで間違いを修正し、aritrsh.ccustnoをtable2.ccustnoに置き換えました。残念ながら、次のエラーが発生しました。[FireDAC] [Phys] [ODBC] [Microsoft] [SQL Serverネイティブクライアント10.0] [SQL Server]無効な列名 'ccustno'。 –
私はccustnoが確かにarinvchとaritrshに存在するSQLサーバのカラム名であることを保証することができます。 –