Hi all, i have following query and trying to do union but get result different
(
SELECT Mrev = '', SUM(testitem.cramount) - SUM(testitem.DebAmount) AS annualtest, DAY(test.date) AS day
FROM test AS test WITH (NOLOCK) INNER JOIN
testItem AS testItem WITH (NOLOCK) ON test.testKey = testItem.testKey INNER JOIN
testaccount AS act WITH (NOLOCK) ON testItem.testcode = act.actCode AND actType = 'S' AND (act.desc LIKE '%Annual%')
WHERE (test.PostDate BETWEEN @firstdayofmonth AND @lastdayofmonth )
GROUP BY DAY(test.date)
)
union
(
SELECT Mrev = '', SUM(testitem.cramount) - SUM(testitem.DebAmount) AS annualtest, DAY(test.date) AS day
FROM test AS test WITH (NOLOCK) INNER JOIN
testItem AS testItem WITH (NOLOCK) ON test.testKey = testItem.testKey INNER JOIN
testaccount AS act WITH (NOLOCK) ON testItem.testcode = act.actCode AND actType = 'S' AND (act.desc LIKE '%monthly%')
WHERE (test.Date BETWEEN @firstdayofmonth AND @lastdayofmonth )
GROUP BY DAY(test.date)
)
but result i get is
monthly annual day
73699.89 0.00 30
122404.09 0.00 13
208177.18 0.00 29
116061.63 0.00 27
0.00 250.11 27
it should be
116061 250.11 27~~
How can i make it happen
(
SELECT Mrev = '', SUM(testitem.cramount) - SUM(testitem.DebAmount) AS annualtest, DAY(test.date) AS day
FROM test AS test WITH (NOLOCK) INNER JOIN
testItem AS testItem WITH (NOLOCK) ON test.testKey = testItem.testKey INNER JOIN
testaccount AS act WITH (NOLOCK) ON testItem.testcode = act.actCode AND actType = 'S' AND (act.desc LIKE '%Annual%')
WHERE (test.PostDate BETWEEN @firstdayofmonth AND @lastdayofmonth )
GROUP BY DAY(test.date)
)
union
(
SELECT Mrev = '', SUM(testitem.cramount) - SUM(testitem.DebAmount) AS annualtest, DAY(test.date) AS day
FROM test AS test WITH (NOLOCK) INNER JOIN
testItem AS testItem WITH (NOLOCK) ON test.testKey = testItem.testKey INNER JOIN
testaccount AS act WITH (NOLOCK) ON testItem.testcode = act.actCode AND actType = 'S' AND (act.desc LIKE '%monthly%')
WHERE (test.Date BETWEEN @firstdayofmonth AND @lastdayofmonth )
GROUP BY DAY(test.date)
)
but result i get is
monthly annual day
73699.89 0.00 30
122404.09 0.00 13
208177.18 0.00 29
116061.63 0.00 27
0.00 250.11 27
it should be
116061 250.11 27~~
How can i make it happen