Grouping and duplicates

  • Hello everybody.

    What i have is a bulk insert procedure that imports the data in a table. So far so good. What i want to do is to check that all data comes in groups like:

    field1, field2, id

    a,a,1

    a,a,2

    a,a,3

    a,b,4

    b,b,5

    a,a,6 <----- this record should not appear here.

    Is there any way doing so ?without using cursors please

    Thanks in advance.

  • ...why?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • There is an aggreement specifying the grouping of the file, thus all groups must be together and in order.

  • If you are concerned with the way the data is ordered when you retrieve it then use an order by clause in the select statement. You can NEVER garantee that your records are going to come out ordered the way you want without it.

    Gary Johnson

    Microsoft Natural Language Group

    DBA, Sr. DB Engineer




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

  • I must export the data just the way they imported. The one that sents me the file has to pefrorm the group by and order clause.The question is how can i check that the imported data are grouped and in order ?

  • If id is sequential, then try this

    select a.field1, a.field2, a.id 
    
    from table a
    left outer join table b
    on b.id = (a.id -1)
    and (b.field1 > a.field1 or b.field2 > a.field2)
    where b.id is not null

    Far away is close at hand in the images of elsewhere.
    Anon.

  • the best way would be to add an identity column to the table so that when you import the data you can preserve the ordering. Then use an order by clause on the export so that you have the same order as the import.

    Gary Johnson

    Microsoft Natural Language Group

    DBA, Sr. DB Engineer




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply