列名称无效' - '

时间:2017-05-13 04:43:21

标签: sql sql-server sql-server-2008 sql-server-express

我在我的计算机上使用SQL Server Express版本并尝试从vb.net应用程序执行以下查询但是我收到此错误

  

列名称无效' - '。

在查询中,我使用' - '字符来执行某些选定字段之间的减法,我认为它应该正常工作,如MSDN所述。

以下是查询:

SELECT 
    r.ID AS [المعرّف],
    ch.ID AS [معرّف القيمة],
    r.active AS مفعّل,
    en.ename AS [الموتور],
    b.location AS [عنوان العلبة],
    c.clientname AS [المشترك],
    p.ampere AS [أمبير],
    cl.fullname AS [الجابي],
    b.code AS [رمز العلبة],
    ec.code AS [الرمز في العلبة],
    ch.previousvalue AS [القيمة السابقة],
    ch.currentvalue AS [القيمة الحاليّة],
    r.insurance AS [تأمين],
    (
        (
            SELECT SUM(total)
            FROM CounterHistory coh
            WHERE coh.regid = r.ID
                AND (
                    coh.cyear < 2017
                    OR (
                        coh.cmonth < 5
                        AND coh.cyear = 2017
                        )
                    )
            ) - (
            SELECT IsNull(Sum(pyy.pvalue), 0)
            FROM CounterHistory coh,
                Payment pyy
            WHERE pyy.counterhistoryid = coh.ID
                AND coh.regid = r.ID
                AND (
                    coh.cyear < 2017
                    OR (
                        coh.cmonth < 5
                        AND coh.cyear = 2017
                        )
                    )
            )
        ) AS [مكسورات],
    ch.notes AS ملاحظات,
    (ar.caption & "-" & ch.cyear) AS [شهر],
    (b.code & ec.code) AS [رمز مفتاح],
    ch.monthlyfee AS [رسم اشتراك],
    (ch.currentvalue - ch.previousvalue) AS [فرق عداد],
    ch.kilowattprice AS [سعر الكيلو],
    (((ch.currentvalue - ch.previousvalue) * ch.kilowattprice) + roundvalue) AS [مطلوب كيلو],
    total + discount AS [المجموع],
    discount AS [حسم],
    (
        SELECT IsNull(Sum(pyy.pvalue), 0)
        FROM CounterHistory coh,
            Payment pyy
        WHERE pyy.counterhistoryid = coh.ID
            AND coh.regid = r.ID
            AND coh.cmonth = 5
            AND coh.cyear = 2017
        ) AS [مدفوع],
    (
        total - (
            SELECT IsNull(Sum(pyy.pvalue), 0)
            FROM CounterHistory coh,
                Payment pyy
            WHERE pyy.counterhistoryid = coh.ID
                AND coh.regid = r.ID
                AND coh.cmonth = 5
                AND coh.cyear = 2017
            ) - discount
        ) AS [باقي]
FROM
    Registration r,
    Client c,
    ElectricBox b,
    ECounter ec,
    CounterHistory ch,
    Package p,
    Engine en,
    Collector cl,
    ArabicMonth ar
WHERE 
    r.packageid = p.ID
    AND ch.cmonth = ar.ID
    AND r.counterid = ec.ID
    AND ec.boxid = b.ID
    AND r.clientid = c.ID
    AND ch.regid = r.ID
    AND b.engineid = en.ID
    AND b.collectorid = cl.ID
    AND ch.cmonth = 5
    AND ch.cyear = 2017
    AND (
        DatePart("yyyy", r.registrationdate) < 2017
        OR (
            DatePart("m", r.registrationdate) <= 5
            AND DatePart("yyyy", r.registrationdate) = 2017
            )
        )
ORDER BY 
    cl.fullname,
    b.code,
    ec.code

1 个答案:

答案 0 :(得分:4)

看起来错误是由此引起的:

(ar.caption & "-" & ch.cyear) AS [شهر],

在SQL Server中,您应该使用'表示字符串,使用+进行连接,如下所示:

(ar.caption + '-' + ch.cyear) AS [شهر],