I have a table defined as follows:
CREATE TABLE KT ( AccountNo VARCHAR(20), StockNames VARCHAR(4000) );
100 "International Business Machines | Conoco Philips | Exxon Inc | American Telegraph and Telephone | McDonalds Inc | JC Penny | Hewlett Packard "
200 "Microsoft Inc | Eastman Kodak | Merck Inc | Pfizer Inc | Dell Inc | Genworth Financial | Synovus Financial | Texas Instruments|"
.
.
I need to split the records into another table (let's call it KT_Output) so that the stock names are put in 2 fields of size 50 chars.
We will fill up as many stock names that can fit in the 50 char field, without splitting the name halfway. The delimiter character '|'
designates the end of a stock name. Another record with the same account number is created if there are more stocks that can fit
in Stock1 and Stock2 fields.
CREATE TABLE KT_Output ( AccountNo VARCHAR(20), Stock1 Varchar(50), Stock2 Varchar(50) )
So, we should have something like the following output:
AccountNo Stock1 Stock2
100 "International Business Machines | Conoco Philips" "Exxon Inc | American Telegraph and Telephone "
100 "McDonalds Inc | JC Penny | "Hewlett Packard"
200 "Microsoft Inc | Eastman Kodak | Merck Inc" "Pfizer Inc | Dell Inc | Genworth Financial"
200 "Synovus Financial | Texas Instruments"
How can I do this?
Thanks in advance for your reply.
CREATE TABLE KT ( AccountNo VARCHAR(20), StockNames VARCHAR(4000) );
100 "International Business Machines | Conoco Philips | Exxon Inc | American Telegraph and Telephone | McDonalds Inc | JC Penny | Hewlett Packard "
200 "Microsoft Inc | Eastman Kodak | Merck Inc | Pfizer Inc | Dell Inc | Genworth Financial | Synovus Financial | Texas Instruments|"
.
.
I need to split the records into another table (let's call it KT_Output) so that the stock names are put in 2 fields of size 50 chars.
We will fill up as many stock names that can fit in the 50 char field, without splitting the name halfway. The delimiter character '|'
designates the end of a stock name. Another record with the same account number is created if there are more stocks that can fit
in Stock1 and Stock2 fields.
CREATE TABLE KT_Output ( AccountNo VARCHAR(20), Stock1 Varchar(50), Stock2 Varchar(50) )
So, we should have something like the following output:
AccountNo Stock1 Stock2
100 "International Business Machines | Conoco Philips" "Exxon Inc | American Telegraph and Telephone "
100 "McDonalds Inc | JC Penny | "Hewlett Packard"
200 "Microsoft Inc | Eastman Kodak | Merck Inc" "Pfizer Inc | Dell Inc | Genworth Financial"
200 "Synovus Financial | Texas Instruments"
How can I do this?
Thanks in advance for your reply.