TSQL:将旧where子句转换为联接语法
我想把这个查询放到“现代连接语法”中TSQL:将旧where子句转换为联接语法,tsql,join,Tsql,Join,我想把这个查询放到“现代连接语法”中 SELECT t.acct_order, c1.acct_desc, c1.position, c1.end_pos, Budget = sum(((g.data_set-1)/2)*(g.debits - g.credits)), Actual = sum(((g.data_set-3)/-2)*(g.debits - g.credits)) FROM glm_chart c1,
SELECT
t.acct_order,
c1.acct_desc,
c1.position,
c1.end_pos,
Budget = sum(((g.data_set-1)/2)*(g.debits - g.credits)),
Actual = sum(((g.data_set-3)/-2)*(g.debits - g.credits))
FROM
glm_chart c1,
glm_chart c2,
glh_deptsum g,
#TEMPTABLE t
WHERE
g.acct_uno=c2.acct_uno
and c1.acct_code = t.acct_code
and c2.position between c1.position and c1.end_pos
and g.debits-g.credits<>0
and c1.book=1
and g.data_set in (1, 3)
and (g.period between 201201 and 201212)
GROUP by t.acct_order,
c1.acct_desc,
c1.position,
c1.end_pos
ORDER by t.acct_order
这就是我要做的,但正如您所看到的,我似乎无法识别表glh_deptsum g到C1或到t的连接
SELECT
t.acct_order,
c1.acct_desc,
c1.position,
c1.end_pos,
sum(((g.data_set-1)/2)*(g.debits - g.credits)) AS Budget,
sum(((g.data_set-3)/-2)*(g.debits - g.credits)) AS Actual,
FROM #TEMPTABLE T
INNER JOIN glm_chart c1 ON c1.acct_code = t.acct_code
INNER JOIN glh_deptsum g <---- HELP WHAT GOES HERE ---------
INNER JOIN glm_chart c2 ON c2.position between c1.position and c1.end_pos AND g.acct_uno=c2.acct_uno
WHERE
g.debits - g.credits <> 0
AND c1.book=1
AND g.data_set in (1, 3)
AND (g.period between 201201 and 201212)
GROUP BY t.acct_order,
c1.acct_desc, c1.position,c1.end_pos
ORDER BY t.acct_order
谁能告诉我我做错了什么吗?看起来应该是这样的:
SELECT t.acct_order,
c1.acct_desc,
c1.position,
c1.end_pos,
Budget = sum(((g.data_set-1)/2)*(g.debits - g.credits)),
Actual = sum(((g.data_set-3)/-2)*(g.debits - g.credits))
FROM #TEMPTABLE t
INNER JOIN glm_chart c1
ON t.acct_code = c1.acct_code
INNER JOIN glm_chart c2
ON c2.position between c1.position and c1.end_pos
INNER JOIN glh_deptsum g
ON c2.acct_uno = g.acct_uno
WHERE g.debits-g.credits<>0
and c1.book=1
and g.data_set in (1, 3)
and (g.period between 201201 and 201212)
GROUP by t.acct_order,
c1.acct_desc,
c1.position,
c1.end_pos
ORDER by t.acct_order
脸掌!啊!!!!!!!!!!!!谢谢你,米奇!谢谢你,我似乎完全忽略了这样一个事实:G在C2之后加入C2,而不是C2在G之后加入G