Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detect missed dates
Message
From
29/01/2019 10:10:23
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01665790
Message ID:
01665799
Views:
53
>Sir I have this data (MS SQLSERVER 2008 TABLE)
>
>
>CREATE CURSOR junk(date t,sno n(3))
>SET DATE YMD
>SET CENTURY on
>
>INSERT INTO junk values({^2019-01-01 01:11:28.000},0)
>INSERT INTO junk values({^2019-01-01 03:21:23.000},0)
>INSERT INTO junk values({^2019-01-02 05:31:22.000},0)
>INSERT INTO junk values({^2019-01-02 15:41:27.000},0)
>INSERT INTO junk values({^2019-01-04 17:51:29.000},0)
>INSERT INTO junk values({^2019-01-04 21:51:19.000},0)
>INSERT INTO junk values({^2019-01-05 02:31:36.000},0)
>INSERT INTO junk values({^2019-01-08 05:21:48.000},0)
>INSERT INTO junk values({^2019-01-08 00:31:59.000},0)
>INSERT INTO junk values({^2019-01-08 18:41:35.000},0)
>INSERT INTO junk values({^2019-01-09 10:11:11.000},0)
>brow
>
>
>I want to UPDATE sno column like this
>
>
>
>Sno changes when date sequence is changed.
>No changes in previous sno if date is going in sequence (no missed date)
>
>Please

I have done this previously, and it involves selecting dates + 1 into a field, and searching for those in the original set, and as long as they do not exist, you keep iterating to find all of the dates that don't exist.
CREATE CURSOR junk(tDatetime t,sno n(3))
SET DATE YMD
SET CENTURY on

INSERT INTO junk values({^2019-01-01 01:11:28.000},0)
INSERT INTO junk values({^2019-01-01 03:21:23.000},0)
INSERT INTO junk values({^2019-01-02 05:31:22.000},0)
INSERT INTO junk values({^2019-01-02 15:41:27.000},0)
INSERT INTO junk values({^2019-01-04 17:51:29.000},0)
INSERT INTO junk values({^2019-01-04 21:51:19.000},0)
INSERT INTO junk values({^2019-01-05 02:31:36.000},0)
INSERT INTO junk values({^2019-01-08 05:21:48.000},0)
INSERT INTO junk values({^2019-01-08 00:31:59.000},0)
INSERT INTO junk values({^2019-01-08 18:41:35.000},0)
INSERT INTO junk values({^2019-01-09 10:11:11.000},0)

CREATE CURSOR c_missing (dDate d)

SELECT MAX(TTOD(tDatetime)) as dMax ;
    FROM junk ;
    INTO CURSOR c_range

SELECT TTOD(tDatetime)+1 AS dDate ;
    FROM junk ;
    WHERE TTOD(tDatetime)+1 < c_range.dMax AND TTOD(tDatetime)+1 NOT IN (SELECT TTOD(tDatetime) FROM junk) ;
    INTO CURSOR c_miss

IF USED("c_miss")
    DO WHILE _tally > 0
        SELECT c_missing
        APPEND FROM (DBF("c_miss"))

        SELECT dDate+1 AS dDate ;
            FROM c_miss ;
            WHERE dDate+1 < c_range.dMax AND dDate+1 NOT IN (SELECT TTOD(tDatetime) FROM junk) ;
            INTO CURSOR c_miss
    ENDDO
ENDIF

SELECT c_missing
BROWSE LAST NOWAIT
Previous
Reply
Map
View

Click here to load this message in the networking platform