0

在此处输入图像描述我正在使用 VB.Net 连接到 SQL Server 2008

这个作品 --> Dim query = "SELECT wo.WorkOrderID, wo.WorkOrderNo FROM dbo.WorkOrder wo"

这不起作用 --> Dim query = "SELECT wo.WorkOrderID, wo.WorkOrderNo, wod.LineNo FROM dbo.WorkOrder wo, dbo.WorkOrderDetails wod"

这也不起作用 --> Dim query = "SELECT wo.WorkOrderID, wo.WorkOrderNo, wod.LineNo FROM dbo.WorkOrder wo, dbo.WorkOrderDetails wod WHERE wo.WorkOrderID = wod.WorkOrderID"

我假设它是因为在 WorkOrderDetails 中 WorkOrderId 有多个相同的 ID

  • 在 WorkOrder 中,WorkOrderID 似乎是增量的.. 1,2,3 等..
  • 在 WorkOrderDetails 中,WorkOrderID 是这样的.. 1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,3 等。

关于如何让它发挥作用的任何想法?我想不明白..

  • 关键字“LineNo”附近的语法不正确。是我得到的错误

我也刚刚尝试过 --> "SELECT WorkOrderID, WorkOrderNo, LineNo FROM dbo.WorkOrder JOIN dbo.WorkOrderDetails ON dbo.WorkOrder.WorkOrderID = dbo.WorkOrderDetails.WorkOrderID"

似乎没有工作..同样的错误

4

2 回答 2

4

LineNo保留关键字。使用分隔标识符

SELECT WorkOrderID, WorkOrderNo, [LineNo]
FROM dbo.WorkOrder
  JOIN dbo.WorkOrderDetails
    ON dbo.WorkOrder.WorkOrderID = dbo.WorkOrderDetails.WorkOrderID
于 2012-05-25T05:19:26.570 回答
0

使用连接:

Dim query = 
"SELECT wo.WorkOrderID,
       wo.WorkOrderNo, 
       wod.[LineNo] FROM dbo.WorkOrder wo
                 JOIN dbo.WorkOrderDetails wod 
                 ON wo.WorkOrderID = wod.WorkOrderID"

该网站将帮助您开始:

sql教程

最好的祝福

于 2012-05-25T05:14:12.333 回答