关键字附近的语法不正确使用子查询

时间:2017-11-03 06:44:47

标签: sql c#-4.0

SELECT DISTINCT dbo.master_order.order_no,
                dbo.master_order.program_no,
                dbo.Setup_size.size_name,
                dbo.Setup_color.color_name,
                dbo.Setup_color.color_no,
                dbo.transaction_production.total_weight,
                dbo.Setup_yarn.yarn_count,
                dbo.Setup_article_order.article_name,
                dbo.master_order.shipment_date,
                @from AS reprt,
                @to AS reprt1,
                dbo.transaction_order.quantity,
                dbo.transaction_order.gsm
FROM dbo.master_order
INNER JOIN dbo.transaction_order ON dbo.master_order.order_id = dbo.transaction_order.order_id
INNER JOIN dbo.transaction_production ON dbo.transaction_order.trans_id = dbo.transaction_production.trans_id
INNER JOIN dbo.Setup_size ON dbo.transaction_order.size_id = dbo.Setup_size.size_id
INNER JOIN dbo.Setup_yarn ON dbo.transaction_order.yarn_id = dbo.Setup_yarn.yarn_id
INNER JOIN dbo.Setup_article_order ON dbo.transaction_order.article_id = dbo.Setup_article_order.article_id
INNER JOIN dbo.Setup_color ON dbo.transaction_order.color_id = dbo.Setup_color.color_id
AND dbo.Setup_yarn.color_id = dbo.Setup_color.color_id
WHERE dbo.setup_color.color_id=
    (SELECT color_no
     FROM dbo.setup_color) WHERE master_order.shipment_date>=@from
  AND master_order.shipment_date<=@to

3 个答案:

答案 0 :(得分:1)

这是WHERE子句

之后的语法
   where dbo.setup_color.color_id=
   (select color_no from dbo.setup_color) 
    where master_order.shipment_date>=
   @from and master_order.shipment_date<=@to

主查询上使用了2个Where子句。

答案 1 :(得分:0)

问题是主查询中有2个WHERE子句。由于master_order是主要查询中使用的表格,因此只需将第二个WHERE替换为AND,如下所示。

SELECT DISTINCT dbo.master_order.order_no,
                dbo.master_order.program_no,
                dbo.Setup_size.size_name,
                dbo.Setup_color.color_name,
                dbo.Setup_color.color_no,
                dbo.transaction_production.total_weight,
                dbo.Setup_yarn.yarn_count,
                dbo.Setup_article_order.article_name,
                dbo.master_order.shipment_date,
                @from AS reprt,
                @to AS reprt1,
                dbo.transaction_order.quantity,
                dbo.transaction_order.gsm
FROM dbo.master_order
INNER JOIN dbo.transaction_order ON dbo.master_order.order_id = dbo.transaction_order.order_id
INNER JOIN dbo.transaction_production ON dbo.transaction_order.trans_id = dbo.transaction_production.trans_id
INNER JOIN dbo.Setup_size ON dbo.transaction_order.size_id = dbo.Setup_size.size_id
INNER JOIN dbo.Setup_yarn ON dbo.transaction_order.yarn_id = dbo.Setup_yarn.yarn_id
INNER JOIN dbo.Setup_article_order ON dbo.transaction_order.article_id = dbo.Setup_article_order.article_id
INNER JOIN dbo.Setup_color ON dbo.transaction_order.color_id = dbo.Setup_color.color_id
AND dbo.Setup_yarn.color_id = dbo.Setup_color.color_id
WHERE dbo.setup_color.color_id=
    (SELECT color_no
     FROM dbo.setup_color)
  AND master_order.shipment_date>=@from
  AND master_order.shipment_date<=@to

如果表dbo.setup_color的值超过1,则使用IN而不是=,或者在内部查询中添加WHERE子句,只返回一个值否则会引发错误。

答案 2 :(得分:0)

使用 而不是等于子查询。

print(soup.get_text(" "))