2

次のクエリを SQL サーバー ベースのコードから TERADATA コードに変換しようとしています。

INSERT INTO #Keyword(Keyword,OmnitureHitsID,Hit_Time_GMT)    
            SELECT  Search, @PrvRowIdentity,Hit_Time_GMT     
            FROM    
            (SELECT     
                Evar02_Search     
            , Hit_Time_GMT     
            , Evar11_End_Keyword     
            , Evar14_End_SrchTrmPassed     
            , Post_Evar02     
            , Post_Evar11     
            , Post_Evar14     
            FROM #MaINTable WHERE ID = @i    
            AND Visid_High =@Visid_High ) p    
            UNPIVOT     
            (SEARCH FOR SearchKeyword IN     
                (Evar02_Search     
                , Evar11_End_Keyword     
                , Evar14_End_SrchTrmPassed     
                , Post_Evar02     
                , Post_Evar11     
                , Post_Evar14 )    
            ) AS unpvt;

UNPIVOT 後にパーツを変換する方法を教えてください。実際、私はそのSEARCH FOR SearchKeyword IN部分が何をするのか分かりません。

どんな助けでも大歓迎です:)

4

2 に答える 2

3

残念ながら、Teradata には関数がありませんが、クエリUNPIVOTを使用して複製できます。UNION ALL

INSERT INTO #Keyword(Keyword,OmnitureHitsID,Hit_Time_GMT)    
SELECT  Search, @PrvRowIdentity, Hit_Time_GMT     
FROM    
(
  SELECT Hit_Time_GMT, Evar02_Search as Search, 'Evar02_Search' as col
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
  UNION ALL
  SELECT Hit_Time_GMT, Evar11_End_Keyword as Search, 'Evar11_End_Keyword' as col       
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
  UNION ALL
  SELECT Hit_Time_GMT, Evar14_End_SrchTrmPassed as Search, 'Evar14_End_SrchTrmPassed' as col       
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
  UNION ALL
  SELECT Hit_Time_GMT, Post_Evar02 as Search, 'Post_Evar02' as col     
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
  UNION ALL
  SELECT Hit_Time_GMT, Post_Evar11 as Search, 'Post_Evar11' as col     
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
  UNION ALL
  SELECT Hit_Time_GMT, Post_Evar14 as Search, 'Post_Evar14' as col     
  FROM #MaINTable 
  WHERE ID = @i    
    AND Visid_High =@Visid_High 
) x

Search現在のクエリの一部は、リストされUNPIVOTている各列の列の値を取得していますSearchKeyword。したがって、これはUNION ALL、各列に対して次を取得するを使用して複製できます。

  • Hit_Time_GMTフィールドごとに
  • Search各列の値 ( Evar02_SearchPost_Evar02など)
  • の最後のフィールドはUNION ALL、値がどの列から来たかを指定します
于 2012-08-08T11:48:14.407 に答える