Friday, February 24, 2012

Array in TSQL

Hi all,

I have data like this :

POHDR;JAKARTA;St.1
DTL;1. ;00248337;8996006855701 ;083;041;002; 7,812.50; 312,500.00; 284,091.00; 8,875.00

first row is the PO header and the second is the detail. This data was collected using Export Import Wizard from flatfile and put it in one column. I want to split the header and the detail into different table and map each column separated by ; to a proper field. For this work I should check every column separated by ; with CHARINDEX function but I have to write the TSQL as much as the count of ;. It would be better if we can use array to simplify the code.

Can we use array in Transact SQL ? since I have no clue referring to SQLBOL. Thanks in advance.

Best regards,

Hery

Hi Hery,

You can add identity column to the table so you can asume that the ids with odd numbers (i.e. 1, 3, 5 ..) as PO Header and the Ids with Even Numbers as Details..

Regarding Arrays.. I am sorry there is no such concept.. but you can go through following link to get it work..

http://www.sommarskog.se/arrays-in-sql.html

Hope this will help you..

|||Hi SajidAttar,

Thanks for the article, it helps me much.

Best regards,

Hery|||

Hi..

Glad to help.. and to be honest.. effort goes to the author..Smile

All the best.

No comments:

Post a Comment