关于把SQL SERVER 2000上的查询转到ACCESS 2000/2002上运行的问题! (200分)

  • 主题发起人 主题发起人 JamesDai
  • 开始时间 开始时间
J

JamesDai

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾,小弟现在遇到一个问题,想请教一下。
下面是一个我在SQL SERVER2000上实现的查询,现要把它转到Access 2000/2002上运行,请问该怎么转?
数据表已全部导到Access数据库中。

SELECT
C.NAME AS '项目',
GLTJ3.*
FROM (
SELECT *
FROM (

SELECT
PEKING,
CATEGORY,
CASE
WHEN (GROUPING(StatItem) = 1 AND PEKING IS NULL AND CATEGORY IS NULL) THEN '000000'
WHEN (GROUPING(StatItem) = 1 AND PEKING = 'Y' AND CATEGORY IS NULL) THEN '000001'
WHEN (GROUPING(StatItem) = 1 AND PEKING IS NULL AND Category = '0101') THEN '010100'
WHEN (GROUPING(StatItem) = 1 AND PEKING IS NULL AND Category = '0102') THEN '010200'
ELSE StatItem
END AS 'ITEM',
COUNT(NUM) AS 总数,
SUM(CASE WHEN WORKLENTH + 1 <= 5 OR WORKLENTH + 1 IS NULL THEN 1 ELSE 0 END) AS '5年及以下',
SUM(CASE WHEN WORKLENTH + 1 > 5 AND WORKLENTH + 1 <= 10 THEN 1 ELSE 0 END) AS '6年至10年',
SUM(CASE WHEN WORKLENTH + 1 > 10 AND WORKLENTH + 1 <= 15 THEN 1 ELSE 0 END) AS '11年至15年',
SUM(CASE WHEN WORKLENTH + 1 > 15 AND WORKLENTH + 1 <= 20 THEN 1 ELSE 0 END) AS '16年至20年',
SUM(CASE WHEN WORKLENTH + 1 > 20 AND WORKLENTH + 1 <= 25 THEN 1 ELSE 0 END) AS '21年至25年',
SUM(CASE WHEN WORKLENTH + 1 > 25 AND WORKLENTH + 1 <= 30 THEN 1 ELSE 0 END) AS '26年至30年',
SUM(CASE WHEN WORKLENTH + 1 > 30 AND WORKLENTH + 1 <= 35 THEN 1 ELSE 0 END) AS '31年至35年',
SUM(CASE WHEN WORKLENTH + 1 > 35 AND WORKLENTH + 1 <= 40 THEN 1 ELSE 0 END) AS '36年至40年',
SUM(CASE WHEN WORKLENTH + 1 > 40 THEN 1 ELSE 0 END) AS '41年及以上'
FROM (

SELECT
SAL_HUMANINFO.NUM,
PEKING,
CASE
WHEN (left(StatItem,4) = '0101') THEN '0101'
WHEN (left(StatItem,4) = '0102') THEN '0102'
END AS CATEGORY,
StatItem,
WORKLENTH
--SALTYPE
FROM
SAL_HUMANINFO, //人员信息表
SAL_HUMANINFO_DETAIL //人员工资信息表
WHERE
SAL_HUMANINFO.NUM = SAL_HUMANINFO_DETAIL.NUM
AND LEFT(StatItem, 2) = '01'

) AS GLTJ1
--GROUP BY StatItem WITH CUBE
GROUP BY PEKING, Category, StatItem WITH CUBE

) AS GLTJ2
WHERE
(PEKING IS NULL AND Category IS NULL)
OR (PEKING = 'Y' AND CATEGORY IS NULL AND ITEM = '000001')
OR (PEKING IS NULL AND CATEGORY = '0101' AND ITEM = '010100')
OR (PEKING IS NULL AND CATEGORY = '0102' AND ITEM = '010200')
--ORDER BY ITEM

) AS GLTJ3 RIGHT OUTER JOIN Code_StatItem C
ON C.Code = GLTJ3.ITEM
WHERE
C.Code <= '000001' OR
(C.Code >= '010100' AND C.Code <= '010200')
 
晕倒,这么长,谁看得明白啊。
Access支持的SQL语法与T-SQL有差异,可以看Access Help.
建议你把子查询单独做成Query.
 
后退
顶部