In Table T there are few columns of which 2 columns are
related to Product – Product Code (col A) and Plan Code (col B). Col A contains
only one value at one time per record. However, Col B can contain more than one
Plan code in a single row. The Plan codes are spread across col B which has
length of 500 chars. Also, Plan Code in col B is appears for every first 3
characters of every 18 characters read. E.g aklsjjhvkjwejbivpwepbvvkbvsa….
, akl and epb are 2 plan codes here in the given string of col B.
Please write a SQL script to get DISTINCT values of Product
Code and Plan Code from Table T. For instance if table T has a record
Looks like homework to us. If we do this for you then you won't have learnt anything ... so we need you to tell us what you have done, what you think you might do, ask questions to help you discover how to etc. etc. There is not point us just doing the query for you ...
SELECT ColA, substring(ColB,1,3)
FROM T
UNION ALL
SELECT ColA, substring(ColB,19,3)
FROM T
but note that that will only partially answer the question
"col B has length of 500 chars ... col B appears for every first 3 characters of every 18 characters" so for data that is longer than the example a more complex solution is needed.
Personally I would use a Tally Table (which you could Google).
This example / question is quite difficult, and your sample answer suggests to me that it is beyond your level of skill, so my advice would be to discuss this with your Tutor / Teacher. Your Tutor / Teacher will then be able to use their experience of teaching you to gauge where the gaps are in your knowledge and help you to understand the issues and gain the knowledge and skill required. It is difficult to do that on a forum as we have no knowledge of what you have learnt so far and and so on.