〜20行の一時テーブルまたは変数を作成する必要があります。テーブル変数とエラー "スカラー変数を宣言する必要があります"
DECLARE @UserDailyStatsForCategories TABLE (
CategoryId uniqueidentifier not null,
[Date] date not null,
[Unique users] int not null,
[Returning users] int not null,
[New users] int not null
);
insert into @UserDailyStatsForCategories (CategoryId, [Date], [Unique users], [Returning users], [New users])
select
@CategoryId,
eventdate,
count(*),
count(case when cnt > 1 then 1 end),
count(case when cnt = 1 then 1 end)
from
(
select cast(eventtime as date) as eventdate, userid, count(*) as cnt
from telemetrydata
where [dbo].[TelemetryData].[DiscountId] = @DiscountId
and [dbo].[TelemetryData].[EventName] = 'DiscountClick'
group by cast(eventtime as date), userid
) date_user
group by eventdate;
それは動作しますが、私は、この追加したとき:
update CategoryDailyStatsTemp
set
[CategoryDailyStatsTemp].[Unique users] = @UserDailyStatsForCategories.[Unique users],
[CategoryDailyStatsTemp].[Returning users] = @UserDailyStatsForCategories.[Returning users],
[CategoryDailyStatsTemp].[New users] = @UserDailyStatsForCategories.[New users]
where [CategoryDailyStatsTemp].[Id] = @UserDailyStatsForCategories.CategoryId
and [CategoryDailyStatsTemp].[Date] = @UserDailyStatsForCategories.[Date];
をそれから私はエラーを得た:
Msg 137, Level 15, State 2, Line 3 Must declare the scalar variable "@UserDailyStatsForCategories".
何が起こっていますか?
'CategoryID' @はUserDailyStatsForCategories' @あなた宣言されたテーブルの列** **'です。後で、宣言された変数を使用するようにこれを使用しようとします。 – Shnugo