SQL Server 2012 :: Enumerating Gaps Between Islands?

Aug 31, 2014

I have a system log with NULL gaps between a sequence of numbers...see "BEFORE" sample below.

The number of gaps between the Sequence_ID's are arbitrary, but generally less then 50 records.

I'd like enumerate the gaps to produce the "AFTER" result, but do it with a single query or view, not through procedures.

I've been playing with windowed functions and groupings with no success. I'm guessing it'll need some recursive CTE logic, but I haven't been able to figure it out the correct loop.

BEFORE:
PK_IDSequence_ID
1035586935587
3035586234 NULL
8355585 NULL
1235584 NULL
4675583 35583
4035582 NULL
6035382 NULL
1435581 NULL
2035580 NULL
3435553 35563
6603589 NULL
9475559 35552

AFTER:

PK_IDSequence_ID
1035586935587
3035586234 3
8355585 2
1235584 1
4675583 35583
4035582 4
6035382 3
1435581 2
2035580 1
3435553 35563
6603589 1
9475559 35552

View 9 Replies


ADVERTISEMENT

Islands And Gaps In Sequential Data

Aug 23, 2007

I couldn't find a topic suitable for testing this, so I thought I'd start one.

Here is one way to get the islands without a tally table.declare@test table (symbol char(3), dt smalldatetime)

insert@test
select'abc','01/01/1990' union all
select'abc','01/02/1990' union all
select'abc','01/03/1990' union all
select'abc','01/04/1990' union all
select'abc','01/05/1990' union all
select'def','01/03/1990' union all
select'def','01/04/1990' union all
select'def','01/05/1990' union all
select'def','01/06/1990' union all
select'def','01/07/1990' union all
select'ghi','01/01/1990' union all
select'ghi','01/02/1990' union all
select'ghi','01/06/1990' union all
select'ghi','01/07/1990' union all
select'ghi','01/08/1990'

selectsymbol,
min(dt),
max(dt2)
from(
selectt1.symbol,
t1.dt,
t2.dt as dt2,
(select count(distinct t3.symbol) from @test as t3 where t3.symbol < t1.symbol and t3.dt <= t1.dt) AS r
from@test as t1
inner join@test as t2 on t2.symbol = t1.symbol
wheret2.dt - 1 = t1.dt
) as d
group bysymbol,
r
E 12°55'05.25"
N 56°04'39.16"

View 16 Replies View Related

T-SQL (SS2K8) :: Count Of Consecutive Years Of Participation (islands And Gaps)

Jun 29, 2015

I have a data set (snippet below) and I need to count the number of consecutive years based on a date in time for each ID as represented below.

ID DATE
------ --------
1 2000-05-03
1 2001-06-10
1 2002-04-02
1 2005-07-29
1 2010-12-15
4 2001-05-07
4 1999-08-01
4 2000-07-05
4 2001-08-01
9 2002-05-01
9 2000-04-02

My result set needs to be something like:

ID Count of Consecutive Years
------- -----------------------------
1 2
4 2
9 0

I know this is a gaps and islands type problem but nothing I have been able to find is working once I attempt modification so that it can fit my dataset. Please note that I am going to use the data return to populate another table that is currently being populated using a cursor that utilizes an insert statement based on different codes.

View 9 Replies View Related

SQL 2012 :: Gaps After Restarting Server

Jun 19, 2012

Create a table with an Identity column, insert data / restart the server / insert more data / restart the server/ insert some more data.

My data looks like this :
Identity column
1
2
3
1002
1003
1004
1005
2002
2004

It looks like the indentity value gain +~1000 after most server restart (sometimes identity stay the same). This can be very dangerous for some datatype! The only thing google told me was this : URL...but microsoft did not comment on it yet!

View 9 Replies View Related

SQL Server 2012 :: Filling Gaps In Date Ranges?

Dec 10, 2014

See sample data below. I want hourly breakdown for the last X years, the month and day will be the same for each year.

SELECT '2013-12-10 04:00:00.000' as dt, 220.50 as amt UNION ALL
SELECT '2013-12-10 06:00:00.000' as dt, 24.50 as amt UNION ALL
SELECT '2013-12-10 07:00:00.000' as dt, 527.50 as amt UNION ALL
SELECT '2013-12-10 08:00:00.000' as dt, 28.50 as amt UNION ALL
SELECT '2013-12-10 11:00:00.000' as dt, 25.50 as amt UNION ALL

[Code] .....

-- expected result

SELECT '2013-12-10 00:00:00.000' AS dt, NULL AS Amt UNION ALL
SELECT '2013-12-10 01:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 02:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 03:00:00.000', NULL AS Amt UNION ALL
SELECT '2013-12-10 04:00:00.000', 220.50 AS Amt UNION ALL

[code].....

View 9 Replies View Related

SQL 2012 :: Gaps In Identity Column

Feb 13, 2014

The identity int column in my sql2012 db is not incrementing properly.

I have a table which uses an int auto identity as a primary key it is sporadically skipping increments, for example:

1, 2, 3, 4, 5, 1004, 1005

This is happening on a random number of tables at very random times...

View 5 Replies View Related

SQL 2012 :: Seed Value Of Identity Columns Jumps / Gaps By 1000 After Restarting It?

Jan 9, 2015

We just switched from Sql server 2008R2 to Sql server 2012.I am facing one problem with identity Columns "When ever i restarts my sql server,the seed value for each identity column is increased by 1000 (For int identity column it is 1000 and for big int it is 10000).

"For Example if seed value of any table was 3 then after restarting sql server will be 1003 if i again restart sql server it will be 2003 and so on."

After searching on google i found that it is a new feature (don't know what is use of it) in sql server 2012 and having only two solution if you want old identity concept

1. Use sequence object -

a) I am using same database in sql server 2008 and 2012 both so can't use sequence in 2008.

b) if i go with sequence then need not change save procedure for each table,which is bulky task for us.

2. Use Trace Flag 272 (-T272)

I can go with this solution because there is need not do any changes in my application.Some one suggested me that add -T272 in startup parameter,after this sql server identity column will work normal as previous version.I did the same but it is not working.

I don't want to do any changes in my database structure.

how to use this -T272 or why it is not working.

I don't want to use this new identity feature how to suppress it. Why -T272 is not working.

View 4 Replies View Related

Enumerating Sql Server Databases

May 4, 2007

Hi. I would like to enumerate all the databases in a given Sql Server instance.
I've searched and found no information. Would somebody post a piece of VB code to do that?
Thanks in advance
Rafael
 

View 3 Replies View Related

Trouble Enumerating SQL Server Instances 32 Bit And 64 Bit Mode

Sep 3, 2007

Hi,

I have a problem enumerating SQL server instances on a 64 bits server W2K3 R2 SP2, running SQL 2000 sp4 (32 bits), SQL 2005 Express sp2 (32 bits) and SQL 2005 Developer sp2 (64 bits).
I am using the same way as the sample (found on SQLDev.net) ListSQLSvr application to enumerate the instances.

In my case i have the following instances defined:

MYPC - SQL 2000 (32 bits) (default) instance
MYPCEXPRESS - SQL 2005 Express (32 bits) instance
MYPCSQL2K5X64 - SQL 2005 Developer (64 bits) instance


When i enumerate the SQL instances for the entire network like this:

ListSQLSvr -X
All instances appear (including the instances from other machines in the network, as expected)

When i enumerate the SQL instances on my local machine like this:
ListSQLSvr -S MYPC -X
Only the 32 bits instances appear..

When compiling the ListSQLSvr application to target 64 bit, the result on the local macine shows only the 64 bits instances !?!?

I am using this enumerating code in my installer to fill a listbox and depending on what kind of SQL instance (32 or 64 bits) is selected by the user, I install the correct extended stored procedure and register accourdingly (note the difference between a 32 extended Proc and a 64 bit extended Proc).
In this case I only need the local SQL instances since i want to install the correct extended proc.

Since the installer (MSI file) is one-for-all (32 and 64 bits OS's) it runs the code from a Custom Action DLL in 32 bits. Resulting in showing only the 32 bits instances.
When I would use the 64 bit installer and make my CA DLL to target 64 bits, I would only see the 64 bits instances.
But i would like to see and use all instances in my 32 bit installer and take the appropriate action to install the correct extended Proc.

I think it has to do with some internals of ODBC (SQLBrowseConnect() most likely); When using a local enumeration it uses Shared Memory and when enumerating the entire network (or any other machine) it uses TCP/IP?
If this is true, is there a way to bypass this someway?
Or if this isn't true, does anyone know any solution to the problem described?


Regards,

Albert van Peppen
Senior System Engineer
Insad Grafisch b.v.

View 17 Replies View Related

Enumerating SQL Server 2005 Servers From The Network

Mar 6, 2008

Hi,

I need to find out whether SQL Server client components are installed on a machine through my application.

For that I was expecting "SOFTWARE\Microsoft\Microsoft SQL Server\90" registry key. BUT If I install just native client drivers, this key is not getting created.

What could be another approch to determine whether system has required client components.

Also I need to list all the SQL Server 2005 servers available in the network. (Similar to the Servers combo box being populated while DSN creation in ODBC Admin tool). There are several approches.

1) Use NetServerEnum API
2) Use SQLBrowseConnect ODBC API
3) Use SQLDMO Object
4) OSQL utility.

Which one I should use VC++ (2005)?


Thanks in advance,
Mac

View 6 Replies View Related

Trouble Enumerating SQL Server Instances With SQL 2000/2005 On Network

Dec 4, 2007



Hi,

We have (after several weeks of testing in all kind of environments) send out a new version of our application to several of our customers. Within days problems where drippin in; After looking for the problem on various customer situations we found a problem which I think is rather disturbing and very odd. I'll describe the situation, on which we finally managed to recreate the problem, here.

In my problem I use the following configuration:

Windows 2003 (standard edition) AD network with 2 domain controllers, multiple Windows XP workstations, some without SQL instances, some with SQL 2000 instances, some with SQL 2005 instances and even one with SQL 7 running.
All run a 32 bit OS.

Tools to reproduce:

ListSQLSvr application (found on SQLDev.net) to enumerate the instances.


Problem description:
--------------------------------------------------
I am running the machine called DEV001, which has SQL 2000 (instancename DRUMIS) and SQL 7.0 (has no instancename so this is the root instance) installed.

In any 'normal' situation all the runnings SQL instances are visible on the network like this:




Code Block
C:>listsqlsvr -X
(local);Clustered:No;Version:7.00.623
ADM002DRUMIS;Clustered:No;Version:8.00.194
DEV001DRUMIS
DEV001DRUMIS;Clustered:No;Version:8.00.194
DEV002DRUMIS;Clustered:No;Version:8.00.194
DEV002EXPRESS;Clustered:No;Version:9.00.3042.00
DEV002EXPRESS
INSADBACKOFFICEDRUMIS;Clustered:No;Version:8.00.194
INSADBACKOFFICEEXACT;Clustered:No;Version:9.00.3042.00
INSADOFFICEWSUS;Clustered:No;Version:8.00.194
SUP001DRUMIS;Clustered:No;Version:8.00.194




When I turn the SQL 2005 Browser service off on the machine called DEV002 the list looks like:




Code Block
C:>listsqlsvr -X
(local);Clustered:No;Version:7.00.623
ADM002DRUMIS;Clustered:No;Version:8.00.194
DEV001DRUMIS;Clustered:No;Version:8.00.194
DEV001DRUMIS
DEV002
DEV002EXPRESS
DEV004DRUMIS;Clustered:No;Version:9.00.3042.00
INSADBACKOFFICEDRUMIS;Clustered:No;Version:8.00.194
INSADBACKOFFICEEXACT;Clustered:No;Version:9.00.3042.00
INSADOFFICEWSUS;Clustered:No;Version:8.00.194
SUP001DRUMIS;Clustered:No;Version:8.00.194




Notice that the browser service might be off on DEV002, you can still see the EXPRESS instance and a new root instance has appeared (though it doesn't exist!)??

After restarting the Browser service all is OK again.

When I turn on Hide Server in the SQL 2000 TCP/IP properties (or turn it on in the registry [HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerDRUMISMSSQLServerSuperSocketNetLibTcp] "TcpHideFlag"=dword:00000001) on the DEV002 computer something real scary is happening..
The list looks as follows:



Code Block
C:listsqlsvr -X
(local)
ADM002
DEV001
DEV002
DEV004
INSADBACKOFFICE
INSADOFFICE
SUP001






When someone has entered a database (for example the backoffice database on INSADBACKOFFICEEXACT) the list looks as follows (for a short moment; 5 secs or so):



Code Block
C:listsqlsvr -X
(local)
ADM002
DEV001
DEV002
DEV004
INSADBACKOFFICEDEVELOP;Clustered:No;Version:8.00.194
INSADBACKOFFICEDRUMIS;Clustered:No;Version:8.00.194
INSADBACKOFFICEEXACT;Clustered:No;Version:9.00.3042.00
INSADOFFICE
SUP001




Notice now that ALL instances are gone and no extended information is available. In the Query Analyser and in the SQL Management Studio when browsing you'll see this as well!
When someone is accessing a database instance it appears for a few seconds again.

Since our installation and applications rely on selecting a existing instance it will fail in the above situations (or at least not showing all available instances).

In my opinion this is a bug somewhere!
Note that even when the SQL Services are stopped on DEV002 (leaving the Browser service running) it still seems to block out ALL instance on the ENTIRE network!

I don't mind that one INSTANCE or even the entire MACHINE is hidden from the network, but ALL instances on ALL machines??

And the SQL Browser issue also worries me a bit since it does not stop the possibily to browse the SQL instances; it removes the SQL2000 instances but adds a root instance which doesn't even exist! Also the extended info is stripped.

Can anyone help me solve this/advise?

Also mind that in any situation there might run a lot of computers with a lot of SQL instances and I cannot tell our customers to find which machine has the SQL TCP/IP properties set to Hide...
It even seems that in some situations SBS 2003 does the hiding automatically on Install? And if so, when and why?

Regards,

Albert van Peppen
Senior System Engineer
Insad Grafisch b.v.

View 31 Replies View Related

Transact SQL :: Grouping Records With A Date Range Into Islands

Nov 18, 2015

I tried to ask a similar question yesterday and got shot down, so I'll try again in a different way.  I have been looking online at the gaps and islands approach, and it seems to always be referencing a singular field, so i can't find anything which is clear to get my head around it.In the context of a hotel (people checking in and out) I would like to identify how long someone has been staying at the hotel (The Island?) regardless if they checked out and back in the following day.

Data example:
DECLARE @LengthOfStay TABLE
(
PersonVARCHAR(8) NOT NULL,
CheckInDATE NOT NULL,
CheckOutDATE NULL

[code]...

View 7 Replies View Related

SQL Server 2008 :: Populate Table With Some Gaps In Between

Mar 28, 2015

I need to populate a table with numbers with some gaps in between with logic below.

first row -1110
last row - 9550

1110
1120
1130
1140
1150

[Code] .....

View 8 Replies View Related

SQL Server 2008 :: What Could Cause Large Gaps In Servers Default Trace

Feb 12, 2015

I have the default trace on a SQL Server 2008R2 instance enabled and found today that there is a gap of nearly 4 minutes in the trace during a time of the day when there most certainly is not going to be a 4 minute window of nothing.

What if anything could cause the default trace to have a gap like this? The SQL Server Instance (against my preferences) is hosted on VMware however it has its on HOST and so its resources are not being shared with any other server. The data & log files reside on different parts of the SANS. Our IT & Network admins are looking into the issue on their end but when I looked and found a near 4 minute gap in the default trace it hit me that this could be something above/outside of SQL Server.

View 1 Replies View Related

Enumerating Instances Without DMO

Jul 23, 2005

Can anyone suggest a method of enumerating instances of MSDE 2000 withoutusing DMO ?Using C++, MFC, and ADO.Thanks

View 2 Replies View Related

Enumerating DTS Packages

Nov 19, 2007



Is it possible, using the SMO Enumerator (or anything else), to access the SQL 2000 DTS package object hierarchy in an SSIS package?

I started with a Script Task, I was planning on using the DMO DLL, but it doesn't look like you can access a COM DLL from the Script Task.

And the SMO Enumerator doesn't seem to enumerate SQL Server 2000 DTS package info....

Thanks...

View 1 Replies View Related

Enumerating Foreach Loop From Rowset

Jan 22, 2007

Please let me know if I am on the right track here.

I have an Execute SQL Task that selects multiple rows from an OLE DB connection, each row containing 3 columns (data types = string, Int32, Int32). In this task ResultSet = "Full result set" and Result Set > Result Name = 0, Variable Name = [User::viewInfo] which is a user variable with Data Type = Object.

I want to use a Foreach Loop Container to enumerate over the result set rows that are contained in the [User::viewInfo] variable described above. For each resultset row I want to breakout the 3 column values and assign them to 3 corresponding variables that can be referenced in a Data Flow in the Foreach Loop.

Current settings for the Foreach Loop Container: Collection > Enumerator = "Foreach ADO Enumerator", Collection > Enumerator Configuration > ADO object source variable = [User::viewInfo], Enumeration mode = "Rows in the first table". On the Variable Mappings page I select the 3 corresponding user variables I want the rowset column values assigned to, with indexes starting at 1 (not 0).

Thanks - Dana Reed

View 1 Replies View Related

SQL Browser Not Enumerating MSDE Instance

Apr 10, 2008

So, here is the scenario. I have a server that is running a MSDE 2000 instance (8.0.2039). Runs just fine. I install another database, this one is SQL 2005 Express (9.0.3042). Both are installed as part of application setups. Now, for various reasons, I have to uninstall the MSDE 2000 application and reinstall it. After the reinstall, the SQL Browser service no longer enumerates the MSDE instance, only the 2005 instance. As a workaround I fixed the MSDE port on the server and the clients, and it works fine. It also works fine when the application is run from the local computer without a fixed port.

Any suggestions?

Thanks,
Mark

View 4 Replies View Related

Read All Variables In A Script Task W/o Enumerating Them

Sep 19, 2007

I'm having trouble with my configurations. All of my configurations are targeting variables and the various properties are all set to expressions containing the targeted variables. I would like (during debugging) to dump out all of the variables.

Is there a way to access all variables from a script task? It looks like you have to enumerate the variables you want in the ReadOnlyVariables or ReadWriteVariables properties. I'd rather not miss one by forgetting to list it.

View 7 Replies View Related

An Error Occurred While Enumerating The Websites On SERVER1

Dec 19, 2007

Hi, I have installed reporting services on 2 servers now and each time I click: "Report Server Virtual Directory", "Report Manager" "Virtual Directory" or "Web Service Identity" in the Reporting Services Configuration Manager I get the following error:
"An error occurred while enumerating the websites on "SERVER1". If "SERVER1" is a remote server, try changing the firewall settings in the operating system to allow the enumeration. The exception details are: Library not registered.
After this I cannot change any settings under these configuration items.

The servers I have tried installing are running Server2003 R2 SP1 x32 & x64.

I have tried changing service accounts, reinstalling IIS, reinstalling Reporting Services, changing website permissions and IIS configuration but I keep getting this same error.

The server is not a remote server nor is there a firewall present. As the error states there is a unregistered library but I don't know which one.

Thanks in advance.

View 2 Replies View Related

Reporting Services :: Enumerating Reports With Subreports?

Jul 27, 2015

Is there a good way in TSQL to:

1. List all SSRS reports containing sub-reports
2. List the SSRS sub reports?

View 2 Replies View Related

Merge Replication Performance Issues, Enumerating Inserts And Updates For Articles...generations And Batches

Oct 8, 2007


We have a SQLServer 2005 Enterprise merge replication publication with SQL Mobile 3.0 subscribers (Windows Mobile 5.0 and 6.0). We do not use pre-computed partitions due to trigger performance issues with an SSIS/ETL application that supplies data to the merge database. We do use the "Optimize" (=true) option, though we have tried this both ways with no significant differences. We use filters and joins for each worker ID (as HOST_ID) from the subscriptions.

The sync times become increasingly worse after we run the snapshot and bring the publication online. I have tried rerunning the snapshots, this helps little, as it often behaves like the subscription was set to reinitialize and forces a big sync (reload of all data) to the subscriber. We have tried much of the obvious (e.g., flattening filters and joins, adding indexes, etc.).

When users are synchronizing, we watch replication monitor and notice that a lot of time is spent processing "enumerating inserts and updates for article [any article]", especially processing the many generations and batches. This is true for any follow-up syncs after the 1st big sync (initializing the subscription).

I read several posts regarding the batches and generations of changes, and decided to try increasing the €œDownloadGenerationsPerBatch€?. I tried adding this parameter to the snapshot agent job, and the job fails each time with a vague message, even with the default value of 100. How do you change this parameter for SQLServer 2005 Enterprise?

Any suggestions?

Thanks in advance,
Matt

View 5 Replies View Related

Gaps In My Key ID Field

Aug 30, 2007

Greetings,

I am new to SQL Server. I've created a database with a key ID field that is set to automatically increment. Well, after adding records I've got some gaps in my numbering and want to renumber from 1 to eof.

What is the best way to do this in SQL Server 2005?

Thank you.

View 4 Replies View Related

Gaps In Integer Ranges

Dec 13, 2004

hello, i have quite a challenge on my hands here and would appreciate any help. :confused:

I have a table variable that stores integer ranges representing times of the day:

select * from @reservations

room date | starttime | endtime
1 2004-12-11 0 1440 (represents an entire day in minutes)
2 2004-12-12 420 1020
3 2004-12-14 200 600
4 2004-12-15 0 200
4 2004-12-15 500 1000


I need to be able to return the minutes that are open for each room. The @reservations table shows me the times that are blocked.

I'd like to analyze each row and return an integer range representing gaps in the day, where 0-1440 represents an entire day.

Based on the @reservations table above, I'd like to write something that returns:

room date starttime endtime
2 2004-12-12 0 420
2 2004-12-12 1020 1440
3 2004-12-14 0 200
3 2004-12-14 600 1440
4 2004-12-15 200 500
4 2004-12-15 1000 1440

This result represents the times in minutes that are available.

I have no clue how to do this without using a numbers table and checking each minute in each day for each row in the table. Id like to not do that because of sheer performance reasons. There is a possiblity that I will have hundreds of rows in the @reservations table.

I was hoping someone could provide some insight as to how to approach this. Thank you ahead of time! :)

View 3 Replies View Related

Adjust Identity Gaps

Apr 6, 2008

Hi,

I have a table with an identity column..How will the identity gaps be adjusted if i delete few records in the table..ie..the sequence should automatically adjusted..Is there any way for this ?

ID Name City
1 abc xyz
2 mexm mcel
3 olekc kcome

Suppose i delete the record where ID=2..still the sequence should be auto adjusted..ie.the record of ID=3 should become ID=2 automatically..there shouldn't be any gaps.

View 8 Replies View Related

Gaps In Borders Between Columns...

Jul 20, 2007



I have a row in my report that has 6 columns. I want to outline the row with a border, but not the column lines in between. So, I went into BorderColor, changed the Default to white and my Top and Bottom colors as Black. The problem is that where the "white" column lines are, they are displaying 1pt gaps in my outline. I tried changing the BorderStyle to Zero, but it wouldn't take it.



See sample of the report here.



Any ideas?



Thanks,



James H.

View 6 Replies View Related

Fill Gaps To The Left

Jan 14, 2008

Hi developers and architects,


I would like to know if it's possible to do "a gap to the left" in transact sql...


I have a table with:

ID Level1 Level2 Level3 Level4
1 NULL NULL 1 2
2 NULL 1 2 3


My results should be:

ID Level1 Level2 Level3 Level4
1 1 2 2 2
2 1 2 3 3


Currently I'm using a cursor to do that but I haven't good performance.

Do you have ideas?


Thanks a lot,

Jérémie

View 3 Replies View Related

Export To PDF Causes Gaps In List

Jan 31, 2008

When I try to export my new report to PDF, I get extra blank lines in my list(s). My report has a list, with another list inside of it (among other textboxes). When I generate the report, or print it to a printer, it prints as expected. If I export to PDF, it adds in a bunch of blank lines into some of the inner lists. It doesn't seem to reflect any issue with the data, but it is consistent where it puts the spaces. Anyone know of any settings I might be missing?

View 3 Replies View Related

Catch Date Gaps In Different Records

Jan 30, 2005

I need to write a procedure to check if I have any gaps in my dates...

Start Date............End Date
10/6/2004............10/6/2005
10/6/2003............10/6/2004
7/10/2003..........10/6/2003
7/10/2002.............7/10/2003

What I need to do is test the End Date to the next row under the Start Date Column. (in bold to clarify) (moving upward from bottom)

sSQL011$ = "SELECT * FROM TableName " & _
"WHERE ID = '" & ID & "'"
Set rs011 = DB.OpenRecordset(sSQL011$, dbOpenDynaset)
Set Data1.Recordset = rs011
rs011.FindFirst "ID = " & ID

With rs011
do while .eof = False

if .eof then
exit sub
end if

if rs011("StartDate") 'from one record, if it is not equal to the Start
Date in the next record then
MsgBox "Gap in Dates for: " + ID

loop

end with




pseudo...
if the end date in one consecutive row is not the same as the start date in the next row then there is a date gap

thanks...

View 3 Replies View Related

T-SQL (SS2K8) :: Finding Gaps In Dates

Mar 25, 2014

I'm trying to find gaps in times in a table of sessions where the session endings aren't sequential. That is, session 1 can start at 10:00 and finish at 10:30, while session 2 started at 10:05 and finished at 10:45, and session 3 started at 10:06 and finished at 10:20. Only the starting times are in order; the ending times can be anywhere after that.Here's a bunch of sample data:

CREATE TABLE #SessionTest(SessionId int,Logindatetime datetime, Logoutdatetime datetime)

INSERT INTO #SessionTest
SELECT '1073675','Mar 3 2014 1:53PM','Mar 3 2014 1:53PM' UNION ALL
SELECT '1073676','Mar 3 2014 2:26PM','Mar 3 2014 3:51PM' UNION ALL
SELECT '1073677','Mar 3 2014 2:29PM','Mar 3 2014 3:54PM' UNION ALL
SELECT '1073678','Mar 3 2014 2:29PM','Mar 3 2014 5:47PM' UNION ALL
SELECT '1073679','Mar 3 2014 2:30PM','Mar 3 2014 3:37PM' UNION ALL

[code]....

View 6 Replies View Related

Historical Prices With Data Gaps

Apr 24, 2008

Hi,

I have a SQL2005 db for tracking the prices of products at multiple retailers. The basic structure is, 'products' table lists individual products, 'retailer_products' table lists current prices of the products at multiple retailers, and 'price_history' table records when the price of a product changes at any retailer. The prices are checked from each retailer daily, but a row is added to the 'price_history' only when the price at the retailer changes.

Database create script:
http://www.boltfile.com/directdownload/db_create_script.sql

Full database backup:
http://www.boltfile.com/directdownload/database.bak

Database diagram:
http://www.boltfile.com/directdownload/diagram_0.pdf

I have the following query to retrieve the price history of a given product at multiple retailers:

SELECT
price_history.datetimeofchange, retailer.name, price_history.price
FROM
product, retailer, retailer_product, price_history
WHERE
product.id = 'b486ed47-4de4-417d-b77b-89819bc728cd'
AND
retailer_product.retailerid = retailer.id
AND
retailer_product.associatedproductid = product.id
AND
price_history.retailer_productid = retailer_product.id

This gives the following results:

2008-03-08 Example Retailer 22.3
2008-03-28 Example Retailer 11.8
2008-03-30 Example Retailer 22.1
2008-04-01 Example Retailer 11.43
2008-04-03 Example Retailer 11.4

The question(s) I have are how can I:

1 - Get the price of a product at a given retailer at a given date/time
For example, get the price of the product at Retailer 2 on 03/28/2008. Table only contains data for Retailer 1 for this date, the behaviour I want is when there is no data available for the query to find the last data at which there was data from that retailer, and use the price from that point - i.e. so for this example the query should result in 2.3 as the price, given that was the last recorded price change from that retailer (03/08/2008).

2 - Get the average price of a product at a given retailer at a given date/time
In this case we would need to perform (1) across all retailers, then average the results

I'd really appretiate anyone's help on this :)

many thanks in advance,

dg

View 17 Replies View Related

Insert Records Into Gaps In Primary Key

Feb 23, 2006

Hi to all,
I'm a new member here and i would like to ask for some help regarding my problem. first i ahve an incremental primary key with format to something like this: 001-01-001, 001-01-002, 001-01-003, etc. My problem is that i want to insert (supply) the 'missing' or 'gaps' in my primary key field like for example: ..., 001-01-067, 001-01-068, 001-01-070. i want to insert the value 001-01-069 after the record 001-01-068. I have several gaps some ranging from several numbers like 005-04-007,005-04-020 which has a 13 records gap. Is there a way for stored procedure to solve this one?Thanks in advance.

View 8 Replies View Related

Records Being Inserted Into Gaps Of Identity Col

Jan 17, 2008

I have a table with the following specifications:

[FutureArticleId] [bigint] IDENTITY(1,1) NOT NULL,
[cFutureArticleTitle] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[cDescription] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[gCategoryId] [bigint] NOT NULL,
[cKeyword] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[bIsDeleted] [bit] NOT NULL CONSTRAINT [DF_tbl_FutureArticle_bIsDeleted] DEFAULT ((0)),
[tOnCreated] [datetime] NOT NULL,
[tOnUpdated] [datetime] NULL,
[gCreatedBy] [bigint] NOT NULL,
[gUpdatedBy] [bigint] NULL,

After some insertions and deletion from the UI, obviously there are gaps in the FutureArticleId column which is an identity column.

However, sometimes while inserting the records the records are being inserted into the gap and not in the next available Identity value.

Is there any table setting which I need to do, to stop this.

Please let me know

Thanks
Ankit

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved