简体   繁体   中英

How write a query in SQL Server 2000?

I have 2 databases with the same tables and views, one in SQL Server 2008 and another in SQL Server 2000.

I wrote this query and it works in SQL Server 2008, but it didn't work in SQL Server 2000.

How can I change my code to work in SQL Server 2000 ?

SELECT 
    SUM(NA_DA) OVER (PARTITION BY vd.SI_VoucherH) AS a,
    SUM(NA_CA) OVER (PARTITION BY vd.SI_VoucherH) AS b
FROM
    acc.ACC_VOUCHERH vh 
INNER JOIN 
    acc.Acc_VoucherD vd ON vh.SI_VoucherH = vd.SI_VoucherH

It's hard to say w/o knowing which table NA_DA & NA_CA are coming from or knowing which table has SI_VoucherH as it PK and which has it a FK.

Hopefully the following will get you close...

SELECT
    vda.NA_DA,
    vda.NA_CA
FROM 
    acc.ACC_VOUCHERH vh 
    JOIN (
            select 
                vd.SI_VoucherH,
                NA_DA = Sum(vd.NA_DA),
                NA_CA = SUM(NA_CA)
            FROM 
                acc.Acc_VoucherD vd 
            GROUP BY
                vd.SI_VoucherH
            ) vda
        on vh.SI_VoucherH=vda.SI_VoucherH;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM