已經構建了一個基本上查看包含所有銀行假期的表並查看當前財政年度的每個月的查詢,然後告訴我有多少工作日可用於工作減去銀行休息室和週末。例如這個月有21個。還有一個累積的提交每月基本累計,所以4 - 2月的累積將會增加所有這些日子。包括創建臨時表的SQL的SSIS作業
在查詢中有一個CreateTable #DATA在最後被刪除,這在Management Studio中正常工作並正常運行。
我的問題是我正在做一個SSIS工作,並保存我的查詢作爲一個SQL文件,並選擇它使用「瀏覽」按鈕。它不允許我繼續,因爲我認爲它有臨時表的問題(見屏幕截圖)
有關如何在保持功能的同時使其工作的任何建議?
請參閱代碼以供參考:
DECLARE @StartDate DATETIME,
@EndDate DATETIME
SELECT @StartDate = (select
case when month(getdate()) >= 4 then
convert(datetime, cast(year(getdate()) as varchar) + '-4-1')
else
convert(datetime, cast(year(getdate())-1 as varchar) + '-4-1')
end),
@EndDate = (select
case when month(getdate()) < 4 then
convert(datetime, cast(year(getdate()) as varchar) + '-3-31')
else
convert(datetime, cast(year(getdate())+1 as varchar) + '-3-31')
end)
CREATE TABLE #data
(
firstday DATETIME NOT NULL PRIMARY KEY,
workingdays INT NOT NULL
);
WITH dayscte ([Date])
AS (SELECT @StartDate
UNION ALL
SELECT Dateadd(DAY, 1, [Date])
FROM dayscte
WHERE [Date] <= @Enddate)
INSERT INTO #data
SELECT MIN([Date]),
COUNT(*) [Day]
FROM table2
LEFT JOIN [dbo].[mydb].[mytable1]
ON [Date] BETWEEN [dbo].[mydb].[mytable1].startdate AND [dbo].[mydb].[mytable1].enddate
where
NOT EXISTS (
SELECT field1,field2 FROM [dbo].[mydb].[mytable1].tscheme_cal WHERE
dayid ='0234572347854234'
AND
[date] <= startdate
AND
[date] >= enddate
)
AND Datename(weekday, [Date]) NOT IN ('Saturday', 'Sunday')
GROUP BY Datepart(MONTH, [Date]),
Datepart(YEAR, [Date])
OPTION (MAXRECURSION 366)
DECLARE @Date DATETIME
SET @Date = (SELECT MIN(firstday)
FROM #data)
SELECT Period,
workingdays [Days_Available] ,
year (firstday) AS [Year]
FROM (SELECT Datename(MONTH, firstday) [Period],
workingdays,
0 [SortField],
firstday
FROM #data
UNION
SELECT Datename(MONTH, @Date) + ' - ' + Datename(MONTH, firstday),
(SELECT SUM(workingdays)
FROM #data b
WHERE b.firstday <= a.firstday) [WorkingDays],
1 [SortField],
firstday
FROM #data a
WHERE
firstday > @Date) data
ORDER BY sortfield,
firstday
DROP TABLE #data
您是否嘗試過 '聲明@data表'? – ChrisBD 2012-02-29 11:44:23
還檢查出我對這個類似問題的答案http://stackoverflow.com/questions/18346484/ssis-package-not-wanting-to-fetch-metadata-of-temporary-table/18360265#18360265 – 2014-12-03 21:28:05