Hi Experts, I have a requirement where in I have to concatenate the fields based on their sequence given in another table along with respect to their lengths. eg.. Input 1: Table A: (below are the fields and their respective values, not all fields will have values) ----------- KSCHL - ZIC0 (KEY)KOTABNR - 521 (KEY)MATNR KUNNR--> 1234567890 LIFNR VKORG--> a234 PRCTR KUNRE--> 4355325363 LIFRE--> 88390234 PRODH --------- Table B:(It contains the same fields as in table A and will have sequence number in which the concatenation should happen. The length field(LEN) will have corresponding field lengths(pipe delimited) should be considered in concatenation) --------- KSCHL - ZIC0 (KEY)KOTABNR - 521 (KEY)MATNR KUNNR--> 1 LIFNR VKORG-->3 PRCTR KUNRE--> 2 LIFRE --> 4 PRODH LEN 10|10|4|10 Expected Result: --------------------- KSCHL - ZIC0 (KEY)KOTABNR - 521 (KEY)MATNR KUNNR 1234567890 LIFNR VKORG a234 PRCTR KUNRE 4355325363 LIFRE 0088390234 PRODH Concat_String 12345678904355325363a2340088390234 Note: If the field length given in Table B doesn't match with actual size of the fields then, the field should be filled with 2 left spaces while concatenation.. Eg. In above example say LIFNR value = 88390234(len =icon_cool.gif then after concat the value should be like below: 12345678904355325363a234 88390234 Note:The fields are not constant..I have around 40 fields like that in which any combination of fields can be possible...eg.. KSCHL - ZIC0 (KEY)KOTABNR - 521 (KEY)MATNR -->2 KUNNR--> 4 LIFNR VKORG-->1 PRCTR KUNRE LIFRE --> 3 PRODH I am not sure which field has the value 1, 2 etc.. and how many fields are forming the combination..It can be sometimes 3/40 fields or it can be 10/40 fields...I have to dynamically get those values and concat... I can have any number of fields for concatenation..above example is just for 4...it should be dynamic enough to handle any number of fields.. Can any one help me on how can I achieve this in SQL... Thanks a lot for your help..
↧