Click here to Skip to main content
15,886,873 members
Home / Discussions / Database
   

Database

 
GeneralRe: Too many results Pin
John R. Shaw18-Apr-08 8:55
John R. Shaw18-Apr-08 8:55 
GeneralRe: Too many results Pin
Blue_Boy18-Apr-08 11:15
Blue_Boy18-Apr-08 11:15 
Generaldata transformation problem for serialised recordsets Pin
uglyeyes17-Apr-08 9:30
uglyeyes17-Apr-08 9:30 
GeneralRe: data transformation problem for serialised recordsets Pin
Michael Potter17-Apr-08 10:08
Michael Potter17-Apr-08 10:08 
GeneralRe: data transformation problem for serialised recordsets Pin
uglyeyes17-Apr-08 13:23
uglyeyes17-Apr-08 13:23 
GeneralRe: data transformation problem for serialised recordsets Pin
Blue_Boy17-Apr-08 15:45
Blue_Boy17-Apr-08 15:45 
GeneralRe: data transformation problem for serialised recordsets Pin
uglyeyes17-Apr-08 16:48
uglyeyes17-Apr-08 16:48 
GeneralRe: data transformation problem for serialised recordsets Pin
Michael Potter18-Apr-08 3:57
Michael Potter18-Apr-08 3:57 
If you are worried about the holes then just use correlated subqueries to find the ranges. A WHERE clause would be a pain since you would end up with a tremendous set of loopped queries if the data was of any real size. See if you can grasp this nasty beast:
SELECT 
    ID,
    Name,
    num AS StartNumber,
    (SELECT
        min(num)
    FROM
        (SELECT 
            ID,
            name,
            num
        FROM 
            TestTable b
        WHERE
            NOT EXISTS (SELECT 
                            * 
                        FROM 
                            TestTable 
                        WHERE
                            ID = a.ID AND 
                            Name = a.Name AND
                            num = b.num+1)) tmp
    WHERE 
        num >= a.num) AS EndNumber
FROM 
    TestTable a
WHERE
    NOT EXISTS (SELECT 
                    * 
                FROM 
                    TestTable 
                WHERE
                    ID = a.ID AND 
                    Name = a.Name AND
                    num = a.num-1)


I tested it with your data set so it works with SQL 2000. Be sure to change the table name (TestTable) and the column names if your database is set up as case sensitive.

The concept comes from finding the start numbers:
SELECT 
    ID,
    name,
    num
FROM 
    TestTable a
WHERE
    NOT EXISTS(SELECT * FROM TestTable WHERE
               ID = a.ID AND Name = a.Name AND
               num = a.num-1) 

and the last numbers:
SELECT 
    ID,
    name,
    num
FROM 
    TestTable b
WHERE
    NOT EXISTS(SELECT * FROM TestTable WHERE
               ID = b.ID AND Name = b.Name AND
               num = b.num+1)

You just have to find a way to put the two queries together in a neat correlated package.
GeneralRe: data transformation problem for serialised recordsets Pin
uglyeyes19-Apr-08 17:26
uglyeyes19-Apr-08 17:26 
GeneralRe: data transformation problem for serialised recordsets Pin
Michael Potter21-Apr-08 3:22
Michael Potter21-Apr-08 3:22 
GeneralGrid sorting wont work on live server (Godaddy) [modified] Pin
AlexeiXX317-Apr-08 5:42
AlexeiXX317-Apr-08 5:42 
Questionhow to change the date 5 th dec 2008 to default date in sqlserver2000? Pin
subbu.sk17-Apr-08 3:59
subbu.sk17-Apr-08 3:59 
AnswerRe: how to change the date 5 th dec 2008 to default date in sqlserver2000? [modified] Pin
Blue_Boy17-Apr-08 15:59
Blue_Boy17-Apr-08 15:59 
GeneralRe: how to change the date 5 th dec 2008 to default date in sqlserver2000? Pin
subbu.sk17-Apr-08 20:03
subbu.sk17-Apr-08 20:03 
GeneralINSERT trigger - how to stop the insert from happening. Pin
Paddy Boyd17-Apr-08 3:53
Paddy Boyd17-Apr-08 3:53 
GeneralRe: INSERT trigger - how to stop the insert from happening. Pin
Werries17-Apr-08 9:56
Werries17-Apr-08 9:56 
GeneralRe: INSERT trigger - how to stop the insert from happening. Pin
SimulationofSai17-Apr-08 21:22
SimulationofSai17-Apr-08 21:22 
GeneralSystem.Data.OleDb.OleDbException: Unspecified error Pin
tom8317-Apr-08 3:35
tom8317-Apr-08 3:35 
GeneralRe: System.Data.OleDb.OleDbException: Unspecified error Pin
Kschuler17-Apr-08 10:37
Kschuler17-Apr-08 10:37 
Generalline 18 is getting error near ''this codes(mysql) Pin
srinivassam17-Apr-08 0:53
srinivassam17-Apr-08 0:53 
GeneralRe: line 18 is getting error near ''this codes(mysql) Pin
R. Giskard Reventlov17-Apr-08 1:16
R. Giskard Reventlov17-Apr-08 1:16 
GeneralCopy from one table into another Pin
.NET- India 17-Apr-08 0:52
.NET- India 17-Apr-08 0:52 
GeneralRe: Copy from one table into another Pin
pmarfleet17-Apr-08 1:57
pmarfleet17-Apr-08 1:57 
GeneralRe: Copy from one table into another Pin
SimulationofSai17-Apr-08 3:04
SimulationofSai17-Apr-08 3:04 
Generalmysql provider problem Pin
srinivassam17-Apr-08 0:28
srinivassam17-Apr-08 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.