Convert audit log to original File

  • Good Morning.

    I have to do an interface between 2 systems but the formats are very different

    System 1 gives me an AuditLog from which I only need to SELECT those where file = EmployeeFile and Date = today

    Date, file, key, field name, old value, new value

    eg

    12/16/16 12:33:01, EmployeeFile, 12345, EmployeeName, George, Ringo

    System 2 needs it in the form of

    key, EmployeeFirstName, Field2,Field 3, Field 4

    -The field names in System2 do not match System1 and need to be specified

    -Conversion logic is needed for some fields

    - the field names do not match

    -There can be multiple changes to the same record on the same day

    I thought of the Union of multiple SQLs for each field possibility, but I thought there must be a better way

    Select

    EmployeeName As EmployeeFirstName

    ,NULL AS Field2

    ,NULL AS Field3

    from

    System1.AuditLog

    regards Paul

  • Hi and welcome to the forum.

    Can you please post the DDL (create table) scripts, some sample data as an insert statement and the expected output?

    😎

  • Dynamic cross-tab queries are dealt with expertly and in great detail in these two Jeff Moden articles:

    http://www.sqlservercentral.com/articles/T-SQL/63681/

    http://www.sqlservercentral.com/articles/Crosstab/65048/

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

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