Return Vertical table to CSV

  • I have a table that has fields in the form of DocID, FieldName, FieldValue

    Here is the table and some representative Data

    CREATE TABLE [dbo].[tblData] (

     [DocID] [int] NOT NULL ,

     [FieldName] [char] (10) ,

     [FieldValue] [char] (10)

    ) ON [PRIMARY]

    Insert into tblData values ('1', 'Field1', 'someinfo')

    Insert into tblData values ('1', 'Field2', 'moreinfo')

    Insert into tblData values ('1', 'Field3', 'evenmore')

    Insert into tblData values ('2', 'Field1', 'somestuff')

    Insert into tblData values ('2', 'Field2', 'morestuff')

    Insert into tblData values ('2', 'Field3', 'evenstuff')

    I need to be able to retrieve this data horizontally and not vertically so that it can be imported into a third party system as a csv.

    For example for the above table I would like the results to be similiar to

    DocID, field1,       field2,             field3

        1,        someinfo,  moreinfo,  evenmore

        2,        somestuff,  morestuff,  evenstuff

    How can I accomplish this?

  • This is a common enough question that we should probably have a sticky for it, but here's what I answered the last time. It is easily modifiable for your needs, but I'll be happy to tailor it for you if you can't on your own.

     

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=305555

Viewing 2 posts - 1 through 1 (of 1 total)

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