我可以让它在 SQL Server Management Studio 中以交互方式工作,但需要在视图中显示这些结果。我对 T-SQL 有点陌生。有没有一种简单的方法可以把它放在一个表中(而不是一个视图)并让它每天早上按计划运行?
Declare @Tempresults TABLE
(
ID varchar(100),
MinLine varchar(100),
MaxLine varchar(100)
)
INSERT INTO @Tempresults (ID, MinLine, MaxLine)
Select PACK_ID, Min(LINE) as MinLine, MAX(Line) as MaxLine
from DESC
group by PACK_ID
Declare @Tempresults2 TABLE
(
ID2 varchar(100),
MinLine2 varchar(100),
MaxLine2 varchar(100),
FirstEntry varchar(500)
)
INSERT INTO @Tempresults2 (ID2, MinLine2, MaxLine2, FirstEntry)
select ID, MinLine, MaxLine, PACK_DESC as FirstEntry
from @Tempresults b, DESC a
where b.ID = a.PACK_ID and b.MinLine = a.line
Declare @Tempresults3 TABLE
(
ID3 varchar(100),
MinLine3 varchar(100),
MaxLine3 varchar(100),
LastEntry varchar(500)
)
INSERT INTO @Tempresults3 (ID3, MinLine3, MaxLine3, LastEntry)
select ID, MinLine, MaxLine, PACK_DESC as LastEntry
from @Tempresults b, DESC a
where b.ID = a.PACK_ID and b.MaxLine = a.line
select a.id2 as ID, b.lastentry as MaxDesc, a.firstentry as MinDesc
from @Tempresults2 a, @Tempresults3 b
Where a.ID2 = b.ID3
group by ID2, FirstEntry, LastEntry