WITH子句的语法错误

时间:2017-05-13 14:10:43

标签: sql sql-server common-table-expression

我正在开发一个Web应用程序,并且有一些冗长的存储过程并且只是试图找出一些东西,我已经提取了存储过程的这部分,但是无法让它工作。这样做的人就是在别名之后创建别名..我只是想得到一个部分来解决它。它抱怨结局,但所有大括号似乎都匹配。提前谢谢..

FInputs是另一个存储过程..整个事情被称为BASE ..这个结果被放在一个临时表中,其全部称为U.我试图将其分解为单独的部分。

;WITH Base AS
(
SELECT 
    * 
FROM F_Inputs(1,1,100021)
),
U AS
(
SELECT
    ISNULL(q.CoverPK,r.CoverPK) AS CoverPK, 
    OneLine,
    InputPK,
    ISNULL(q.InputName,r.InputName) AS InputName,
    InputOrdinal,
    InputType,
    ParentPK,
    InputTriggerFK,
    ISNULL(q.InputString,r.InputString) AS InputString,
    PageNo,
    r.RatePK,
    RateName,
    Rate,
    Threshold,
    ISNULL(q.Excess,r.Excess) AS Excess,
    RateLabel,
    RateTip,
    Refer,
    DivBy,
    RateOrdinal,
    RateBW,
    ngRequired,
    ISNULL(q.RateValue,r.RateValue) AS RateValue,
    ngClass,
    ngPattern,
    UnitType,
    TableChildren,
    TableFirstColumn,
    parentRatePK,
    listRatePK,
    NewParentBW,
    NewChildBW,
    ISNULL(q.SumInsured,0) AS SumInsured,
    ISNULL(q.NoItems,0) AS NoItems,
    DisplayBW,
    ReturnBW,
    StringBW,
    r.lblSumInsured,
    lblNumber,
    SubRateHeading,
    TrigSubHeadings,
    ISNULL(q.RateTypeFK,r.RateTypeFK) AS RateTypeFK,
    0 AS ListNo,
    0 AS ListOrdinal,
    InputSelectedPK,
    InputVis,
    CASE 
        WHEN ISNULL(NewChildBW,0) = 0
        THEN 1
        WHEN q.RatePK is NOT null
        THEN 1
        ELSE RateVis
    END AS RateVis,
    RateStatus,
    DiscountFirstRate,
    DiscountSubsequentRate,
    CoverCalcFK,
    TradeFilter,
    ngDisabled,
    RateGroup,
    SectionNo
FROM BASE R
LEFT JOIN QuoteInputs Q
    ON q.RatePK = r.RatePK
    AND q.ListNo = 0
    AND q.QuoteId = 100021 )

1 个答案:

答案 0 :(得分:0)

好吧,我已经在评论部分解释了这个问题。我再次在这里做,所以未来的读者会更容易找到答案。

WITH子句是查询的一部分。它可以即时创建视图,例如:

with toys as (select * from products where type = 'toys') select * from toys;

最后没有查询,语句无效(无论如何都没有多大意义;如果想要一个永久视图供以后使用,可以使用CREATE VIEW代替)