Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 2 rows to flag 1 Blank and the preceding the same.

Author  Topic 

bhaasjoshi
Starting Member

17 Posts

Posted - 2009-08-18 : 06:07:39
Data

Col1 Col2
A
A x
A
B
B
B
B y

I need an output containing the first 2 rows for 'A' since col2 of 2nd row is not blank, and the 3rd and 4th rows for 'B' since the 4th row is not blank.

So basically I need to flag those records which are not blank in combination with preceding record which are blank.

Please help.

Regards.

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-08-18 : 06:15:52
is there any key or id column available in the table?

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

bhaasjoshi
Starting Member

17 Posts

Posted - 2009-08-18 : 06:17:19
No Sir. No ID/Key. I tried using LEAD or LAG Function but couldn't get it to work properly.

Thanks.
Go to Top of Page

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-08-18 : 06:29:48
any date column? otherwise how to identify which are the consecuative rows?

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

bhaasjoshi
Starting Member

17 Posts

Posted - 2009-08-18 : 06:36:48
Well, there are other columns dates etc but the data is already sorted etc, Its just that my final output will only consist of the records I mentioned.
Go to Top of Page
   

- Advertisement -