0

私はこれをストアドプロシージャに持っています:

select * into #temp_UNION from 
(
  SELECT 6 AS InteractionType, * FROM history.GetHistoryRewardPointsForIncentiveOption (588,1,6)
   UNION all
   SELECT 8 AS InteractionType, * FROM history.GetHistoryRewardPointsForIncentiveOption (558,1,8)
 ) a

これは次のようになります。

interaction type  historyid         incentiveprogramid       points  
 6              1                  1               50
 6                  1                  4                   50
 6              1                      5                   50
 8                  1                  3                  100
 8              1                  4              100

で、〜がある:

select tu.InteractionType,ipc.Name,tu.Points from #temp_UNION tu
 inner join Incentive.IncentiveProgramCultures ipc
on tu.IncentiveProgramId = ipc.IncentivePrograms_IncentiveProgramId
 inner join Zinc.Users zu
on zu.Cultures_DefaultCultureId = ipc.IncentiveProgramCultureId
 where zu.UserId = 588


6   India - Q2 Incentive    50
8   India - Q2 Incentive    100

ここで、上から取得した名前とポイントを使用して、#CategoriesTable(以前に定義された)のフィールドであるHintTextを作成する必要があります。

UPDATE #CategoriesTable
SET HintText = CASE WHEN HasAssessment = 1 
                    THEN 'Program ' + tu.name + ' will earn you ' + tu.points
                    ELSE 'With No Assessment' 
                END 

しかし、tu.Nameでエラーが発生します:マルチパート識別子をバインドできませんでしたか?どうすれば達成できますか?2行の別の一時テーブルを使用する必要がありますか?

ここに新しいコード:

 select * into #temp_UNION from 
(
 SELECT 6 AS InteractionType, * FROM history.GetHistoryRewardPointsForIncentiveOption (588,1,6)
 UNION all
 SELECT 8 AS InteractionType, * FROM history.GetHistoryRewardPointsForIncentiveOption (558,1,8)
 ) a

 select tu.InteractionType,ipc.Name,tu.Points,zu.UserId  into #temp1 from #temp_UNION tu
 inner join Incentive.IncentiveProgramCultures ipc
 on tu.IncentiveProgramId = ipc.IncentivePrograms_IncentiveProgramId
 inner join Zinc.Users zu
 on zu.Cultures_DefaultCultureId = ipc.IncentiveProgramCultureId
 where zu.UserId = 588

Select * from #temp1 t
UPDATE #CategoriesTable
  SET HintText = CASE WHEN HasAssessment = 1 
                    THEN 'Program ' + t.Name + ' and points = ' + t.Points
                    ELSE 'With No Assessment' 
                END 
FROM #temp1 t
WHERE t.userId = #CategoriesTable.UserId

DROP TABLE #temp_UNION 
DROP TABLE #temp1

SELECT *
FROM #CategoriesTable

#CategoriesTableを取得していませんか?

4

1 に答える 1

1

update句で「tu」エイリアスを指定する必要があります

UPDATE #CategoriesTable
SET HintText = CASE WHEN HasAssessment = 1 
                THEN 'Program ' + tu.name + ' will earn you ' + tu.points
                ELSE 'With No Assessment' 
            END 
FROM #temp_UNION tu
WHERE tu.? = #CategoriesTable.? --JOIN condition
于 2013-01-03T11:01:55.493 に答える