I got a table with some questionnarie columns and some questions with sub_questions. For sub question rows Parent Question ID in assigned to parent_ID

Ex: TableA:

[sid] [gid] [qid] [ParentId] [SQID][questions]
AA 100 1 0 - Q1
AA 100 2 0 - Q2
AA 100 3 2 a q1
AA 100 4 2 b q2
AA 100 5 0 - Q3

From the above table I need the results with joining all the columns and questions.
Where as If qid comes in ParentId then qid row will not appear, but its question will concatenate with parentId row question and ID forms with ParentId and SQID

Expecting Result:
[ID] [Question]
AA-100-1 Q1
AA-100-2a Q2-q1
AA-100-2b Q2-q2
AA-100-5 Q3

Please help me in this to get the solution..

Kalaiselvan R
Love Yourself First....