Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to get data where value is null


how to get data where value is null

Author
Message
sachince61
sachince61
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 76
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..
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16518 Visits: 13210
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.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
sachince61
sachince61
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 76
Thank You Very Much...

Its so helpful to me..
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search