SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find gaps in sequence
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

the_roof
Starting Member

2 Posts

Posted - 04/27/2012 :  23:41:11  Show Profile  Reply with Quote
Hello so I looking for help how to find a gap in sequence with two different columns? The values are startbates and endbates

thanks!

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 04/27/2012 :  23:47:38  Show Profile  Reply with Quote
can you post some sample data and the expected result ?


KH
Time is always against us

Go to Top of Page

the_roof
Starting Member

2 Posts

Posted - 04/28/2012 :  00:12:11  Show Profile  Reply with Quote
Begcontrol Opposingstartbates opposingendbates
FXGFluegel000000001 FXGFluegel000000001 FXGFluegel000000001
FXGFluegel000000002 FXGFluegel000000002 FXGFluegel000000002
FXGFluegel000000003 FXGFluegel000000003 FXGFluegel000000003
FXGFluegel000000004 FXGFluegel000000004 FXGFluegel000000004
FXGFluegel000000005 FXGFluegel000000005 FXGFluegel000000006
FXGFluegel000000007 FXGFluegel000000007 FXGFluegel000000008
FXGFluegel000000009 FXGFluegel000000009 FXGFluegel000000009

Want to find the gaps. There are 604085 rows of data.
Thanks!
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 04/28/2012 :  00:14:13  Show Profile  Reply with Quote
and your expected result please.

Also explain how do you consider "gap" based on which columns ?


KH
Time is always against us


Edited by - khtan on 04/28/2012 00:15:24
Go to Top of Page

vinu.vijayan
Posting Yak Master

India
227 Posts

Posted - 04/28/2012 :  06:32:09  Show Profile  Reply with Quote
How do you define "gaps" and which columns are we looking into??

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47157 Posts

Posted - 04/28/2012 :  18:54:49  Show Profile  Reply with Quote
quote:
Originally posted by vinu.vijayan

How do you define "gaps" and which columns are we looking into??

N 28° 33' 11.93148"
E 77° 14' 33.66384"


it would be much better if you can try posting some solutions also rather than simply repeating what others have already suggested.
I'm seeing this happening frequently of late!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bitsmed
Yak Posting Veteran

Denmark
99 Posts

Posted - 04/29/2012 :  19:57:08  Show Profile  Reply with Quote
quote:
Originally posted by the_roof

Begcontrol Opposingstartbates opposingendbates
FXGFluegel000000001 FXGFluegel000000001 FXGFluegel000000001
FXGFluegel000000002 FXGFluegel000000002 FXGFluegel000000002
FXGFluegel000000003 FXGFluegel000000003 FXGFluegel000000003
FXGFluegel000000004 FXGFluegel000000004 FXGFluegel000000004
FXGFluegel000000005 FXGFluegel000000005 FXGFluegel000000006
FXGFluegel000000007 FXGFluegel000000007 FXGFluegel000000008
FXGFluegel000000009 FXGFluegel000000009 FXGFluegel000000009

Want to find the gaps. There are 604085 rows of data.
Thanks!


Maybe this is what you're looking for

select substr(max(b.opposingendbates),1,10)+right('00000000'+convert(varchar,cast(substr(max(b.opposingendbates),10,9) as int)+1),9) as from_missing
      ,a.to_missing
  from (select substr(a.opposingstartbates,1,10)+right('00000000'+convert(varchar,cast(substr(a.opposingstartbates,10,9) as int)-1),9) as to_missing
          from table as a
               left outer join table as b
                       on b.opposingendbates=substr(a.opposingstartbates,1,10)+right('00000000'+convert(varchar,cast(substr(a.opposingstartbates,10,9) as int)-1),9)
         where b.begcontrol is null
       ) as a
       left outer join table as b
                    on b.opposingendbates<a.to_missing

I know its not pretty (and maybe also very slow), but it might work.

This has not been tested for type/syntax error.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000