我在查询中计算了许多新列,我想知道是否可以将查询结果保存到新表/工作表中。因此,当我打开新表时,我可以看到查询结果,而不必每次打开 SQL 时都重新运行查询。
这是我正在使用的代码:
SELECT a.[CUSIP NUMBER],
a.[CURRENT BALANCE],
a.[ORIGINAL WA MATURITY],
a.[CURRENT WA MATURITY],
a.[PASS THRU RATE] [PASS THRU RATE],
a.[CURRENT FACTOR],
b.[CURRENT FACTOR],
b.[ORIGINAL BALANCE],
MonthlyRate,
Payment,
InterestPayment,
Principle,
ScheduledFace,
PreviousFace,
ScheduledFactor,
SMM,
CPR
FROM DBO.mbs032013 a
JOIN dbo.mbs042013 b ON a.[CUSIP NUMBER] = b.[CUSIP NUMBER]
CROSS APPLY (Select (a.[PASS THRU RATE]*.01)/12) CA(MonthlyRate)
CROSS APPLY (Select (a.[CURRENT BALANCE] * ((MonthlyRate)/((1-(1/power(1+ MonthlyRate, a.[CURRENT WA MATURITY]))))))) CA2(Payment)
Cross Apply (Select a.[CURRENT BALANCE] * MonthlyRate) CA3 (InterestPayment)
Cross Apply (Select Payment - InterestPayment) CA4 (Principle)
Cross Apply (Select a.[ORIGINAL BALANCE] * a.[CURRENT FACTOR]) CA5 (PreviousFace)
CROSS APPLY (Select PreviousFace - Principle) CA6(ScheduledFace)
Cross Apply (Select ScheduledFace/a.[ORIGINAL BALANCE]) CA7 (ScheduledFactor)
Cross Apply (Select 100 * (1-(b.[CURRENT FACTOR]/ScheduledFactor))) CA8(SMM)
Cross Apply (Select (1-(power(1-SMM/100,12)))*100) CA9 (CPR)
WHERE a.[CURRENT WA MATURITY] != 0 and a.[CURRENT BALANCE] != 0 and a.[CUSIP NUMBER] = '31416hag0'
该查询最终会生成一个名为“CPR”的函数用于债券分析,我想将这些结果和其他列添加到永久表中。
我正在使用 SQL Server 2012。谢谢!