What I'm basically trying to do is fire off multiple SQL statements in one go. This works fine as long as they don't return results.
What I want to do is make a temporary table fill it and join it on my existing data:
CREATE TABLE #JaarMaandTable(jaarm int,maandm int)
INSERT INTO #JaarMaandTable (jaarm,maandm) VALUES (2013,9), (2013,10), (2013,11)
SELECT jaarm,maandm, kr.*
FROM #JaarMaandTable jm
LEFT JOIN (
SELECT DATEPART(Month, datum) as maand, DATEPART(Year, datum) as jaar ,count(*) as regels mytable
FROM agenda
WHERE datum >= '20130901'
AND datum <= '20131130'
GROUP BY DATEPART(Year, datum), DATEPART(Month, datum)
)kr ON jm.jaarm = kr.jaar AND jm.maandm = kr.maand ORDER BY jaarm, maandm
This is to make use of a temp table to split up results in months even when there's no data for those months.
It works fine in query analyser.
When I try to use "open" on this query, it tells me it doesn't return a cursor. When I "execsql" it, it won't return results. When I split it up, it immediately forgets the #temptable.
ExecSQL, or something similar).