0

何度もループして結果を一時テーブルに列 points_mth1、points_mth2、points_mth3 に追加する一連のスクリプトがありますが、まだテーブルにない顧客の新しい行を挿入する必要がある場合があります。 .

開始 @EndDate が入力され、次の 2 か月間実行したい (例: 2014-02-01、2014-03-01 & 2014-04-01)

以下にループを追加して、次の 2 か月間実行するにはどうすればよいですか?

SET NOCOUNT ON

DECLARE @EndDate DateTime

SET @EndDate = '2014-02-01' 

[set of scripts will be run]

結果は一時テーブルに保存され、実行されるたびに新しい列が追加されます。

IF object_id(N'tempdb..#temp', N'U') IS NOT NULL     DROP TABLE #temp
SELECT j1.customerno, SUM(points)[points_mth1]        ---> this will store the figures for the first date, then a new column [points_mth2] and [points_mth3]
into #temp
FROM customer j1
JOIN #customer_final j2 ON
j1.customerno= j2.customerno
GROUP BY j1.customerno
4

1 に答える 1