fetch multiple rows with single string

  • Hello friends,
    I am having table which contains data stdentname,teachername,subjectname as below.

    Studentname                      Teachename                 Subject
    Atish                                    Praveen                        chemistry
    Atish                                    Abhas                           Maths
    Atish                                     Mahesh                       Physics
    Aarav                                   Praveen                       chemistry
    Aarav                                   Sagar                            Biology

    I want output like below:

    Dear Atish,
    Thank you for enrollment with us . You have enrolled for below courses.

    1. Chemistry under Mr Praveeen
    2.Maths under  Mr.Abhas
    3. Physics under Mr Physics

    Please contact for further details with respective faculty mentioned above.

    Please help me to write sql in exact above format with studentwise.

    Thank you
    Abhas.

  • abhas - Sunday, December 23, 2018 5:03 AM

    Hello friends,
    I am having table which contains data stdentname,teachername,subjectname as below.

    Studentname                      Teachename                 Subject
    Atish                                    Praveen                        chemistry
    Atish                                    Abhas                           Maths
    Atish                                     Mahesh                       Physics
    Aarav                                   Praveen                       chemistry
    Aarav                                   Sagar                            Biology

    I want output like below:

    Dear Atish,
    Thank you for enrollment with us . You have enrolled for below courses.

    1. Chemistry under Mr Praveeen
    2.Maths under  Mr.Abhas
    3. Physics under Mr Physics

    Please contact for further details with respective faculty mentioned above.

    Please help me to write sql in exact above format with studentwise.

    Thank you
    Abhas.

    Heh... so you want to us to help you duplicate the grammatical and alignment errors? :blink:

    You've been around long enough to know you'll get a better response if you take some interest in your own problem by posting data in a readily consumable format.  Please see the article at the first link in my signature line below under "Helpful Links" in my signature line below.  Also, show us what you've tried on your own.  This isn't a mind-blowing problem and most people who have "SQL" in their job description should be able to hammer out such a thing.

    As a bit of a sidebar, you'd do much better if you'd export the correct data to support a mail merge with a word processor.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden - Sunday, December 23, 2018 8:48 AM

    Heh... so you want to us to help you duplicate the grammatical and alignment errors? :blink:

    You've been around long enough to know you'll get a better response if you take some interest in your own problem by posting data in a readily consumable format.  Please see the article at the first link in my signature line below under "Helpful Links" in my signature line below.  Also, show us what you've tried on your own.  This isn't a mind-blowing problem and most people who have "SQL" in their job description should be able to hammer out such a thing.

    As a bit of a sidebar, you'd do much better if you'd export the correct data to support a mail merge with a word processor.

    Ho ho ho, SQL Santa said it all (+100)
    😎

  • Although it has gone quiet from the OP, Mail Merge, especially MS Word does not like nested data sets and most commercial mailing houses seem to struggle with it too.  Where I have had to do this in the past for email templates, I have constructed the nested data into an HTML <TABLE> structure using STUFF...FOR XML

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply