Hide records with duplicate value in column

  • How can i stop duplicate values from within a COLUMN being displayed?

    For example:

    COL1 COL2

    1 abc

    1 abc123

    2 abc321

    3 abc321

    Would look like this:

    COL1 COL2

    1 abc

    abc123

    2 abc321

    3 abc321

    I can do this using reporting services but is it possible to do it directly in a query?

    cheers,

  • Here You Go...

    CREATE TABLE [dbo].[Tab2](

    [c3] [int] NOT NULL,

    [c4] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

    ) ON [PRIMARY]

    Go

    INSERT INTO Tab2

    SELECT 1,'A' UNION ALL

    SELECT 2,'B' UNION ALL

    SELECT 2,'C' UNION ALL

    SELECT 2,'A' UNION ALL

    SELECT 3,'A' UNION ALL

    SELECT 3,'A' UNION ALL

    SELECT 4,'A' UNION ALL

    SELECT 5,'A' UNION ALL

    SELECT 5,'A' UNION ALL

    SELECT 6,'A'

    ;WITH PRV AS

    (

    SELECT C3,c4,

    ROW_NUMBER() OVER (ORDER BY c3) AS rownum

    FROM Tab2

    )SELECT case WHEN a.c3 = b.c3 THEN '' ELSE cast(a.c3 AS varchar(100)) end,a.c4 FROM PRV a

    LEFT OUTER JOIN PRV b ON b.rownum = a.rownum -1

    I think thats the solution you were asking...

    Atif Sheikh

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

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

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