而不是输入'NXT_US.dbo。'一遍又一遍,我怎么能这样做?
SELECT DISTINCT
NXT_US.dbo.icsp.prod, NXT_US.dbo.icsp.descrip##1, NXT_US.dbo.icsp.descrip##2, NXT_US.dbo.icsw.whse, NXT_US.dbo.sastn.descrip AS branch, NXT_US.dbo.icsw.qtyonhand, NXT_US.dbo.icsp.unitstock AS UOM, NXT_US.dbo.apsv.vendno AS VendorNumber,
NXT_US.dbo.apsv.name AS VendorName, NXT_US.dbo.icsp.prodcat, NXT_US.dbo.sasta.descrip, NXT_US.dbo.icsw.prodline, NXT_US.dbo.icsw.statustype, NXT_US.dbo.icsw.lastinvdt, NXT_US.dbo.oeel.invoicedt, NXT_US.dbo.icsw.avgcost, NXT_US.dbo.oeel.vendno,
NXT_US.dbo.icsw.avgcost * NXT_US.dbo.icsw.qtyonhand AS ExtCost, NXT_US.dbo.oeel.prodcost, NXT_US.dbo.oeel.orderno
INTO InventoryView
FROM NXT_US.dbo.sasta INNER JOIN
NXT_US.dbo.icsp ON NXT_US.dbo.sasta.codeval = NXT_US.dbo.icsp.prodcat LEFT OUTER JOIN
NXT_US.dbo.icswu ON NXT_US.dbo.icsp.prod = NXT_US.dbo.icswu.prod LEFT OUTER JOIN
NXT_US.dbo.icsw LEFT OUTER JOIN
NXT_US.dbo.oeel ON NXT_US.dbo.icsw.lastinvdt = NXT_US.dbo.oeel.invoicedt AND NXT_US.dbo.icsw.whse = NXT_US.dbo.oeel.whse AND NXT_US.dbo.icsw.prod = NXT_US.dbo.oeel.shipprod RIGHT OUTER JOIN
NXT_US.dbo.sastn RIGHT OUTER JOIN
NXT_US.dbo.icsd ON NXT_US.dbo.sastn.cono = NXT_US.dbo.icsd.cono AND NXT_US.dbo.sastn.codeval = NXT_US.dbo.icsd.divno ON NXT_US.dbo.icsw.whse = NXT_US.dbo.icsd.whse ON NXT_US.dbo.icsp.prod = NXT_US.dbo.icsw.prod LEFT OUTER JOIN
NXT_US.dbo.apsv ON NXT_US.dbo.icsw.arpvendno = NXT_US.dbo.apsv.vendno
WHERE (NXT_US.dbo.sasta.cono = '1') AND (NXT_US.dbo.sasta.codeiden = 'c') AND (NXT_US.dbo.icsw.statustype = 's') AND (NXT_US.dbo.icsp.cono = '1') AND (NXT_US.dbo.sastn.codeiden = 'V') and NXT_US.dbo.icsw.whse = 'G010'
答案 0 :(得分:0)
第一次在FROM子句中使用它时对每个表进行别名。然后,您可以在SELECT,WHERE,GROUP BY子句中使用别名。这是一个例子(但使用比我在这里放置的通用更好的别名):
SELECT DISTINCT
t2.prod, t2.descrip##1, t2.descrip##2, t4.whse, t6.descrip AS branch, t4.qtyonhand, t2.unitstock AS UOM, t8.vendno AS VendorNumber,
t8.name AS VendorName, t2.prodcat, t1.descrip, t4.prodline, t4.statustype, t4.lastinvdt, t5.invoicedt, t4.avgcost, t5.vendno,
t4.avgcost * t4.qtyonhand AS ExtCost, t5.prodcost, t5.orderno
INTO InventoryView
FROM NXT_US.dbo.sasta AS t1 INNER JOIN
NXT_US.dbo.icsp AS t2 ON t1.codeval = t2.prodcat LEFT OUTER JOIN
NXT_US.dbo.icswu AS t3 ON t2.prod = t3.prod LEFT OUTER JOIN
NXT_US.dbo.icsw AS t4 LEFT OUTER JOIN
NXT_US.dbo.oeel AS t5 ON t4.lastinvdt = t5.invoicedt AND t4.whse = t5.whse AND t4.prod = t5.shipprod RIGHT OUTER JOIN
NXT_US.dbo.sastn AS t6 RIGHT OUTER JOIN
NXT_US.dbo.icsd AS t7 ON t6.cono = t7.cono AND t6.codeval = t7.divno ON t4.whse = t7.whse ON t2.prod = t4.prod LEFT OUTER JOIN
NXT_US.dbo.apsv AS t8 ON t4.arpvendno = t8.vendno
WHERE (t1.cono = '1') AND (t1.codeiden = 'c') AND (t4.statustype = 's') AND (t2.cono = '1') AND (t6.codeiden = 'V') and t4.whse = 'G010'