2

我写了以下简短的视图:

--DROP VIEW ReportObjects.vStarts;
CREATE VIEW ReportObjects.vStarts AS
SELECT *
FROM ReportObjects.vLotHistory
WHERE
        LotType = 'Some constant value'
    AND CDOName = 'Some constant value'
    AND SpecId = 'Some constant value'

当我执行此脚本然后单击 SSMS 视图上的“设计”时,我得到以下信息:

SELECT ContainerName, SpecName, ProductName, LotStatus, CDOName, ResourceName AS LotType, EmployeeName AS WorkflowName, LotType AS DieQty, 
                  WorkflowName AS LotQty, DieQty AS TxnDate, LotQty AS TxnDateGMT, TxnDate AS ContainerId, TxnDateGMT AS HistoryMainlineId, ContainerId AS ProductId, 
                  HistoryMainlineId AS SpecId, ProductId AS WorkflowId, SpecId AS WorkflowBaseId, WorkflowId AS WorkflowStepId, WorkflowBaseId, WorkflowStepId, ResourceId, 
                  EmployeeId
FROM     ReportObjects.vLotHistory
WHERE  (LotType = 'Some constant value') AND (CDOName = 'Some constant value') AND (SpecId = 'Some constant value')

看到问题了吗?DieQty AS TxnDate, LotQty AS TxnDateGMT, TxnDate AS ContainerId 它的别名columnAcolumnC!

我已经尝试过多次删除/重新创建视图。我知道可以说这SELECT *很恶心,但这不是重点(有时在生产代码中是必要的)。

上面的视图是从另一个定义为的视图中选择的:

CREATE VIEW ReportObjects.vLotHistory AS
SELECT
    lot.ContainerName,
    hist.SpecName,
    hist.ProductName,
    lot.Status LotStatus,
    hist.CDOName,
    hist.ResourceName,
    hist.EmployeeName,
    lot.csiLotType LotType,
    WorkFlowBase.WorkflowName,
    hist.Qty DieQty,
    hist.Qty2 LotQty,
    hist.TxnDate,
    hist.TxnDateGMT,
    lot.ContainerId,
    hist.HistoryMainlineId,
    hist.ProductId,
    hist.SpecId,
    Workflow.WorkflowId,
    Workflow.WorkflowBaseId,
    hist.WorkflowStepId,
    hist.ResourceId,
    hist.EmployeeId
FROM ODS.MES_Schema.Container lot
    LEFT JOIN ODS.MES_Schema.HistoryMainline hist
        ON lot.ContainerId = hist.ContainerId
    LEFT JOIN ODS.MES_Schema.WorkflowStep WS
        ON hist.WorkflowStepId = WS.WorkflowStepId
    LEFT JOIN ODS.MES_Schema.Workflow
        ON WS.WorkflowId = Workflow.WorkflowId
    LEFT JOIN ODS.MES_Schema.WorkflowBase
        ON WorkflowBase.WorkflowBaseId = Workflow.WorkflowBaseId

有谁知道为什么 SSMS 或 SQL Server 会吃掉我的查询并吐出废话?请注意,我没有使用 SSMS 工具来创建视图——我使用CREATE VIEW的是如上所示。

4

0 回答 0