Implement logic in a stored procedure

Database
td
Fan

Implement logic in a stored procedure

Hi All,

Need some direction to write the below logic in a SP

Assuming we have a Table A having below data:

Id               Value

110               A

110               T

110               B

112               C

112               P

115               Z 

A particular 'Id' does not have a fix number of records as shown above and it may vary.

Output should look like as follows: 

110              A,T,B

112              C,P

115              Z

Thanks

2 REPLIES

Re: Implement logic in a stored procedure

There is a built in function available in teradata that can be used to achieve this. Check for Function availability in your TD Version with the below query :

 

SELECT FunctionName FROM dbc.FunctionsV

WHERE FunctionName = 'XMLAGG';

If the function exists, you can use a below query to achieve the results :

SELECT ID_column,  TRIM(TRAILING ',' FROM (XMLAGG(Value_column || ',' ORDER BY Value_column ) (VARCHAR(10000))))

FROM your_table_name

GROUP BY 1;

Teradata Employee

Re: Implement logic in a stored procedure

Or you can simply search for Transpose logic. Should be able to prepare 1 SELECT in SP and run it to INSERT in a table.