How to pivot horizontally Author names, and group by Book title. One row per book with multiple authors

I have 3 tables - Book, Author, BookAuthorReference
A book can have multiple authors, and when I do straight query I get multiple rows per book
SELECT <columns>
FROM Book b, Author a, BookAuthorReference ba
where ba.BookId = b.BookId and
ba.AuthorId = a.AuthorId
I want to get the results as ONE row per book, and Authors separated by commas, like:
SQL 2008 internals book    Paul Randal, Kimberly Tripp, Jonathan K, Joe Sack...something like this
Thank you in advance

This can by done by straying into XML land. The syntax is anything but intuitive, but it works. And moreover, it is guaranteed to work.
SELECT b.Title, substring(a.Authors, 1, len(a.Authors) - 1) AS Authors
FROM   Books b
CROSS  APPLY (SELECT a.Author + ','
              FROM   BookAuthorReference ba
              JOIN   Authors a ON a.AuthorID = ba.AuthorID
              WHERE  ba.BookID = a.BookID
              ORDER  BY ba.AuthorNo
              FOR XML PATH('')) AS a(Authors)
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • How to remove author  name and/or date from blogsite summary

    Hello,
    Can someone please help me find how and where to remove the author name from the blogsite summary?
    I don't want any author name listed, just the linked title of the blog post and the date posted.
    Or, is it possible to have the linked title, with 50 words of article displayed, but no author name or date created?
    Thank you very much in advance!

    Yes, thank you.
    The site is still temporary: http://sculpturebythelakes.businesscatalyst.com/index.html
    The "Latest News" box on the right hand column.
    Ideally, I would like a linked post title, a return <BR> and then a set quantity of words below with "read more" following.
    It seems there should be a template to edit, but I've gone through everything I can find in BC backend, and looked at every tutorial I can find (they are all very general, just getting started stuff) and can't figure it out.
    Any help is greatly appreciated.

  • How to get the class name and field name dynamically

    Hi
    I have a class (ex: Contract) the fields (ex : a,b,c) .i need to get the class name and field name dynamically
    ex
    if( validation file for the field Contract.a){
    return contract.a;
    }else if(validation file for the field Contract.b){
    return contract.b;
    how to pass the field name and object dynamically
    Please help me .............
    Thanks in Advance..
    Edited by: 849614 on Aug 11, 2011 6:49 AM

    YoungWinston wrote:
    maheshguruswamy wrote:
    Agreed, but IMO, i still feel its best if there is no tie in between consumer class level details and the database it talks to. A service layer is needed in between them.Sounds like you've done a bit of this before. Me, I've either been a modeller/DBA, doling out data, or a nuts and bolts programmer (and actually more toolmaker than apps, but did a bit of that too).
    Do you know of a good book about the "middle ground" (ie, these service layers)? I understand it empirically, but haven't had a lot of exposure to it.
    Winston
    Edited by: YoungWinston on Aug 11, 2011 10:34 PM
    PS: Apologies. Edited my previous post, presumably while you were composing your reply, when I finally realized what '.filed' meant.Most of my work is in web development, never been a DBA :) . The biggest 'concern' in my shop is 'separation of concerns'. The UI group reports up to a different IT head, the DB group reports up to a different IT head and so on. The looser the coupling between these systems, the lesser the project costs (Integration, QA etc) are. Martin Fowler's books contain good information about separation of concerns in an enterprise environment. The two books which i recommend are
    [url http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420]Enterprise Application Architecture and
    [url http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683/ref=pd_sim_b_1]Enterprise Integration Patterns

  • How to change data source name and context root during deployment

    Hi,
    Env:
    WLS 10.1.3
    JDev 11.1.1.6
    Hudson
    I need to deploy two instances of my ADF application on the same development enviroment. We are using Hudson to deploy. My question is how to change data source name and application context root before second deployment.
    Kuba

    I don't believe there is an inbuilt facility to do this.
    Previously how I've done this is when checking files out using Hudson jovs, before the build I then use an Ant extension called XmlTask (http://www.oopsconsultancy.com/software/xmltask/) to modify the required XML files.
    Can I ask why you're doing this in the first place please? Multi-tenancy? 2 versions of the same app?
    CM.

  • How to create a new user and group on command line?

    Hi,
    I am trying to install INN, the news server on OS X.4.8 (non-server), but it requires me to create a user and group, both called 'news'.
    I know this has something to do with using Netinfo to create them, but I am logged in remotely via ssh and I can't use Netinfo Manager.
    How do I create new users and groups via the command line.
    Thanks for any help.
    PowerMac G5 2x2.7GHz   Mac OS X (10.4.8)  

    I've put some shell scripts that do this here,
    and descriptions
    add_user
    addgroup

  • How to strip a file name and add it to array

    Hello I am new to labview, and I need to know how to strip a file name and add it to an array. For example, filename joe.csv, then take "joe" and add it to an array with other inputs. A visual depiction will be very helpful
    Attachments:
    channel read and error check R03_v9(JHK).vi ‏101 KB

    What does your code attachment have to do with your question?
    What are "other inputs"?
    I assume you have an array of strings. You can strip the filename using get file extension. You can build an array using build array. Wire the existing array on one input ant the string as a second input.
    LabVIEW Champion . Do more with less code and in less time .

  • APEX application  version, author name and date  (history)

    Hello,
    I have created few application in APEX ,I want to add version, author name and date for that application's.
    Please help wherein I can enter in APEX like in Oracle form (pre-form trigger we can add.)
    Thank you in advance.
    Regards,
    Gaurav Nagpal.

    Hi,
    I have never used Forms, so I'm not exactly know what you mean.
    But APEX application definition have version attribute that you can use.
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/bldr_attr.htm#CHDGJHDC
    And you can add author and date to e.g. application comment
    http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/bldapp_comment.htm#CHDBGHJG
    Regards,
    Jari
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • How to Rename the technical name and description of an infocube?

    Hi,
    How to Rename the technical name and description of an infocube?
    Thanx in advance,
    Ravi.

    Ravi,
    You cant change the Technical name of the cube but you can change the description of the Cube. If you want to have a Cube with the same properties and with different Techname and Description better you do copy from the base cube and rename as per your requirement.
    Regards,
    Gattu.

  • How to get report Server Name and Environment ID in Report

    How to print report Server Name and Environment ID in Report 10G.(Through in package or others)
    I'm also using Oracle Application Server 10G.

    Hi,
    Server and envid are the parameters passed along with Reports URL call.
    These variables value can be traped in Report by defining SERVER , ENVID named user parameters.
    Once trapped, can be printed on Report.
    Just ensure that these users parameters are not exposed to Parameter page, otherwise user may end up changing it.
    Thanks

  • My brother gave me his old ipod how do I remove his name and put my name on it so itunes will reconignes me

    My brother gave me his classic ipod, how do I remove his name and put my name so my itunes will recognize my computer?

    Hello Darryll,
    Welcome to the Apple Support Communities. If you want to change the name of the iPod, the following article assist with getting that setup for you.
    iTunes 11: Frequently used features
    http://support.apple.com/kb/HT5649
    Then you can change the name and sync the ipod with your library
    iTunes and iOS: Change the name of your iPhone, iPad, or iPod
    http://support.apple.com/kb/ht3965
    Connect your device and open iTunes.
    In the source list (the left-hand column of iTunes), double-click the name of your device.
    Type the new name for your device and press Return on the keyboard.
    Sync the device (press Sync in the bottom right corner of the screen).
    Regards,
    -Norm G.

  • How do we get register code and group ?

    ji,
    how do we get register code and group based on device category?

    Use the below FM to fetch the equipment number
    ISU_DET_DEVICE_FROM_DEVLOC                                           
    X_DEVLOC                =        device location  
    X_KEYDATE             =       sy-datum
    Then call the below function to get euipment details
    ISU_DB_EZWG_SELECT_METER   
    X_EQUNR        =                equnr 
    X_AB               =            sy-datum
    Alternately
    Pass device location in table Egerh & fetch the equipment and register group. Then pass equnr in table ETDZ to fetch register code.
    Edited by: vikrant guptarya on Jul 20, 2011 2:46 AM

  • I try to open I photo and  I get the message, your iPhoto library is damaged...please restore from backup. But i din't made backup copy. How can i delete previous library and work wrom the new one?

    I try to open I photo and  I get the message, your iPhoto library is damaged...please restore from backup. But i din't made backup copy. How can i delete previous library and work wrom the new one?

    Try this (assuming you're using iPhoto 12): make a temporary, duplicate copy of the library and try the three fixes below in order as needed:
      Fix #1
    delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your Home/Library/Preferences folder. 
    delete iPhoto's cache files that are located in your Home/Library/Caches/com.apple.iPhoto folder.
    reboot, launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding the the Option key.  You'll also have to reset the iPhoto's various preferences.
    Fix #2
    Launch iPhoto with the Command+Option keys depressed and follow the instructions to rebuild the library.
    Select options #1, #2 and #6. 
    Fix #3
    Rebuild the library using iPhoto Library Manager as follows:
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • HT4623 I have an ipad3, iPhone3gs and iPhone5, my problem is my apple ID works all 3 devices but I need a second ID for the iPhone 5. How do I delete my ID and set up a new one for the iPhone5 but keeping my own apple ID for the iPad and iPhone 3GS

    I have an ipad3, iPhone3gs and iPhone5, my problem is my apple ID works all 3 devices but I need a second ID for the iPhone 5. How do I delete my ID and set up a new one for the iPhone5 but keeping my own apple ID for the iPad and iPhone 3GS.

    http://support.apple.com/kb/he37

  • I have forgotten my appleID password and the email it is linked to is deactivated, security questions aren't working. This is on my iPhone and iTunes acs so I can't sync with my new computer. How do I merge AppleID accounts and shut down the old one?

    I have forgotten my appleID password and the email it is linked to is deactivated, security questions aren't working. This is on my iPhone and iTunes acs so I can't sync with my new computer. How do I merge AppleID accounts and shut down the old one (when I have no password and the security questions aren't working?)

    You cannot merge Apple ID accounts, that has never been supported.
    You can contact the Apple ID Security folks per the listing in http://support.apple.com/kb/HT5699 and they can help reset security questions and get the account working.

Maybe you are looking for

  • Subtracting in ALV report

    i have a FI report where i am showing Assets and liabilities value in ALV format, i m using ALV grid layout. there i can easily add those values, but my problem is i have to subtract liabilities value from Assets value, but in ALV i do not find any o

  • Saving to or Exporting to Adobe pdf causes apps to crash

    I run the CS4 Premium dDesign suite on IMac OS 10.6.2 All my CS4 Adobe products: Photoshop, InDesign and Illustrator crash when I try to export or save to pdf.  Fireworks does as well.  Has anyone out there encountered this problem?  Is this a bug? 

  • 0xc000021a BSOD

    Lenovo THinkServer TD340. 32GB RAM, 2 SSD 1 HDD.There is a RAID integrated card. RAID 0 was setup for 2 separate drives since they need to be separate storage drives. Got BSOD trying to install 2012 R2. Had to plug the drive directly into the MB in a

  • Dreamweaver CS4 and PHP require_once, require, include_once, include absolute paths

    I have a question about Dreamweaver CS4's new functionality that lists required and included files in a second row below the name of the file you are currently editing. It's handy. I see that Dreamweaver attempts to list all the included files for a

  • JRE 1.4.0 and Java3d

    Hello everybody! I've installed in my computer (win 98) every jre since the jre1.1.4. So, i've desinstalled them, in order to put in the 1.4.0. But when i try to install java3d, it tells me that it can't find java vm, others errors have appeared alwa