T-SQL Code Help

  • Hi All,

    Here is my sample source file

    Advert,Network,Program

    Acorn,NULL,NULL

    NULL,AC,NULL

    NULL,NULL,Adult

    and I want

    Advert,Network,Program

    Acorn,AC,Adult

    Please help/guide, its urgent.

    Thank You in Advance.

  • Quick solution using aggregation to remove the null values

    😎

    USE tempdb;

    GO

    SET NOCOUNT ON;

    ;WITH SAMPLE_DATA(Advert,Network,Program) AS

    ( SELECT 'Acorn',NULL,NULL UNION ALL

    SELECT NULL,'AC',NULL UNION ALL

    SELECT NULL,NULL,'Adult'

    )

    SELECT

    MAX(SD.Advert ) AS Advert

    ,MAX(SD.Network ) AS Network

    ,MAX(SD.Program ) AS Program

    FROM SAMPLE_DATA SD;

    Results

    Advert Network Program

    ------ ------- -------

    Acorn AC Adult

  • Thank You so much for your reply and help.

    It was just a sample data here is in detail sample file

    Advert,Network,Program

    Acorn,NULL,NULL

    NULL,AC,NULL

    NULL,NULL,Adult

    Jame,Null,Null

    Null,IC,Null

    Null,Null,Young

    Null,Null,Adult

    Fix,Null,Null

    Null,GM,Null

    Null,Null,Kid

    The first three rows are set of Advert = Acorn

    Second four rows are set of Advert = Jame

    and last three rows are set of Advert = Fix

    Please advise.

    Thank You.

  • Have a look at this post for a more complete answer

    😎

  • I really appreciate your time/hard work and awesome code.

    Thank You!

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

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