无效的列名“-”

invalid column name '-'

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

Invalid column name '-'.

在查询中,我使用“-”字符在某些选定字段之间执行减法,我认为它应该可以正常工作,如 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

看起来错误是由这个引起的:

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

在 SQL 服务器中,您应该对字符串使用 ',对连接使用 +,如下所示:

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