how to get data where value is null

  • Hello,

    I have a table with data like below

    id value

    1 2

    2 4

    3 6

    4 NULL

    5 8

    6 NULL

    7 NULL

    8 12

    9 15

    10 NULL

    11 20

    12 NULL

    and i need output like below

    id value

    1 2

    2 4

    3 6

    4 6

    5 8

    6 8

    7 8

    8 12

    9 15

    10 15

    11 20

    12 20

    please help..

  • I managed to write some code that doesn't use a cursor, so hooray for performance 🙂

    SELECT

    ID = tmp.ID

    ,Value = t3.[Value]

    FROM

    (SELECT t1.[ID]

    ,MaxID = MAX(t2.ID)

    FROM [dbo].[Test] t1

    INNER JOIN [dbo].[Test] t2 ON [t1].[ID] >= [t2].[ID] AND t2.[Value] IS NOT NULL

    GROUP BY t1.[ID]) tmp

    INNER JOIN [dbo].[Test] t3 ON tmp.[MaxID] = t3.[ID]

    Please read the link in my signature on how to post questions and sample data. It will make the life of people who are trying to answer your question easier.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thank You Very Much...

    Its so helpful to me..

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

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