I am trying to convert the following query from SQL server based code to TERADATA code.
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;
Can anyone tell me how to convert the part after UNPIVOT. Actually I am not sure what the SEARCH FOR SearchKeyword IN part does.
Any help is appreciated 🙂
Unfortunately, Teradata does not have an
UNPIVOTfunction but you can replicate it using aUNION ALLquery:The
Searchpart of your currentUNPIVOTquery is getting the value for the columns in each of theSearchKeywordcolumns listed. So this can be replicated by using aUNION ALLthat gets the following for each column:Hit_Time_GMTfor each fieldSearchvalue for each of the columns (Evar02_Search,Post_Evar02, etc)UNION ALLjust specifies which column the value came from