我真的很想創建一個視圖。在視圖中使用臨時表
我知道你不能在MSSQL2005視圖中使用臨時表。如果不重寫sql,有沒有什麼明顯的我錯過了?
備份計劃是使用存儲過程。
乾杯
select * into #temp from vwIncidents
SELECT vwIncidents.incidentcode, employeecode, EMPOS.POS_L4_CDA as areaAtTimeOfIncident
into #temp1
FROM vwIncidents
INNER JOIN EMPOS ON vwIncidents.employeecode = EMPOS.DET_NUMBERA
WHERE EMPOS.POS_STARTC < vwIncidents.incidentdate
AND (EMPOS.POS_ENDD > vwIncidents.incidentdate OR EMPOS.POS_ENDD IS NULL)
order by incidentcode
select #temp.*, #temp1.areaAtTimeOfIncident from #temp
left outer join #temp1 on #temp.incidentcode = #temp1.incidentcode
and #temp.employeecode = #temp1.employeecode
order by incidentcode
我敢肯定,你可以刪除第一ORDER BY ... – 2010-04-26 03:55:31