-1

下面的代码可以正常工作,直到我尝试按“Prior_Usage”列排序查询时出现语法错误。任何帮助都会非常有用,因为我花了几个小时寻找解决方案

SELECT TOfferItem.id AS OfferID,
       TOfferItem.fkmanfitemid,
       tblManfItems_1.manf_code AS Code,
       tblManfItems_1.short_desc,
       tblCompany_1.companyname AS Manufacturer,
       tblManfItems_1.target_ounce_size AS Target_Size_Oz,
       tblgeneralitems.longdesc AS [Group],
       tblManfItems_1.quality AS Quality,
       tblitempacks.packdesc AS Pack,
       [quantity] * [weight] AS Avail_Weight,
       TOfferItem.price AS Cost,
       tblcity.city,
       tblstates.stateabbr,
       TOfferItem.note,
       Count(tblmanfitemfiles.id) AS CountOfFiles, 
       tblManfItemCustLINK_1.cust_review,
       tblManfItemCustLINK_1.rating,
       [quantity] * [weight] AS lbs,
       (SELECT SUM(podtl.totallbl)
        FROM tblorderstatus
        INNER JOIN (podtl
        INNER JOIN (pohdr
        INNER JOIN tblcompany ON pohdr.customer = tblcompany.pkcompanyid)
                              ON podtl.tranid = pohdr.tranid)
                              ON tblorderstatus.orderid = pohdr.tranid  
        WHERE (
              ( ( tblorderstatus.submitted ) = true )
              AND ( ( tblorderstatus.canceled ) = false )
              AND ( ( pohdr.customer ) = 1319 )
              AND ( ( podtl.fkmanfitemid ) = TOfferItem.fkmanfitemid ) )
        ) AS Prior_Usage
FROM   tblmanfitemcustlink AS tblManfItemCustLINK_1
       RIGHT JOIN ((tblcompany AS tblCompany_1
                    RIGHT JOIN (tblstates
                                RIGHT JOIN (tblcity
                                            RIGHT JOIN (tblgeneralitems
                                                        RIGHT JOIN (tblitempacks
                                                                    RIGHT JOIN (
                                                        tblofferiteminventory AS
                                                                   TOfferItem
                                            INNER JOIN tblmanfitems
                                                       AS
                                                       tblManfItems_1
                                                    ON
                                            TOfferItem.fkmanfitemid =
                                            tblManfItems_1.id)
                                                    ON tblitempacks.id =
                  tblManfItems_1.pack)
                  ON tblgeneralitems.itemid =
                  tblManfItems_1.commodity_id)
                  ON tblcity.cityid = TOfferItem.fkcityid)
                  ON tblstates.stateid = tblcity.state)
                  ON tblCompany_1.pkcompanyid = tblManfItems_1.fk_company_id)
                   LEFT JOIN tblmanfitemfiles
                          ON tblManfItems_1.id = tblmanfitemfiles.itemid)
               ON tblManfItemCustLINK_1.fkmanfitemid = tblManfItems_1.id
GROUP BY TOfferItem.id,
         TOfferItem.fkmanfitemid,
         tblManfItems_1.manf_code,
         tblManfItems_1.short_desc,
         tblCompany_1.companyname,
         tblManfItems_1.target_ounce_size,
         tblgeneralitems.longdesc,
         tblManfItems_1.quality,
         tblitempacks.packdesc,
         TOfferItem.price,
         tblcity.city,
         tblstates.stateabbr,
         TOfferItem.note,
         tblManfItemCustLINK_1.cust_review,
         tblManfItemCustLINK_1.rating,
         [quantity] * [weight]
HAVING ( ( ( TOfferItem.id ) IN ( 4280, 4287, 4288, 4292,
                                  4295, 4298, 4299, 4300,
                                  4301, 4384, 4401, 4404,
                                  4405, 4410, 4421, 4432,
                                  4435, 4455, 4458, 4459,
                                  4460, 4462, 4469, 4471,
                                  4472, 4473, 4474, 4475,
                                  4479, 4482, 4483, 4484,
                                  4487, 4489, 4494, 4498,
                                  4499, 4500, 4501, 4502,
                                  4503, 4504, 4506, 4508,
                                  4509, 4510, 4512, 4513,
                                  4514, 4515, 4516, 4517,
                                  4524, 4525, 4531, 4532,
                                  4533, 4534, 4535, 4536,
                                  4537, 4538, 4539, 4540,
                                  4541, 4542, 4543, 4544,
                                  4545, 4546, 4547, 4548,
                                  4549, 4550, 4551, 4552,
                                  4553, 4554, 4555, 4556,
                                  4557, 4558, 4560, 4561,
                                  4562, 4563, 4564, 4565, 4566 ) )
         AND ( ( [quantity] * [weight] ) > 0 ) ) 
4

1 回答 1

0

不是答案。一个问题,由于某种原因我无法发表评论。

当您在 SELECT. 删除其中一个,因为它们都做同样的事情,但标签不同。

您在哪里/如何将 Prior_Usage 放在 GROUP BY 中?

只是几个问题。对不起。那里的括号也有点过分。

于 2013-05-08T01:07:25.937 回答