Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Partition Results


Partition Results

Author
Message
UnionAll
UnionAll
SSC-Enthusiastic
SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)

Group: General Forum Members
Points: 194 Visits: 637
There is a heap like the one shown below:

USE tempdb;

CREATE TABLE Heap
(
[Column 0] NVARCHAR(100)
);

INSERT Heap ([Column 0])
VALUES ( '01 Hdr' )
,( 'Command(s) completed successfully.' )
,( 'Create Debug Section' )
,( 'New Query' )
,( 'Splendid. Try Me!' )
,( '01 Trl' )
,( '02 Hdr' )
,( 'Command(s) completed successfully.' )
,( 'Create Debug Section' )
,( '02 Trl' );

SELECT * FROM Heap;



This data is from a flat file imported to an extract (staging) table.

I'm trying to write a query that return the following result:

CREATE TABLE Result
([Column 0] NVARCHAR(100)
, PartitionId INT )

INSERT Result ([Column 0], PartitionId)
VALUES ( '01 Hdr', 1 )
,( 'Command(s) completed successfully.', 1 )
,( 'Create Debug Section', 1 )
,( 'New Query', 1 )
,( 'Splendid. Try Me!', 1 )
,( '01 Trl', 1 )
,( '02 Hdr', 2 )
,( 'Command(s) completed successfully.', 2 )
,( 'Create Debug Section', 2 )
,( '02 Trl', 2 );

SELECT * FROM Result



Hdr and Trl stands for header and trailer respectively.
We need to use Substring([Column 0], 4, 3) to determine if it's a header or trailer and match first two characters between header and trailer to find a partition.

I appreciate your help. Please let me know if I need to better explain my question. Thanks.
Neeraj Dwivedi
Neeraj Dwivedi
SSC Eights!
SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)SSC Eights! (905 reputation)

Group: General Forum Members
Points: 905 Visits: 1320
Let me ask you one question. What I can see from your result that, once you get 'Trl' from Substring([Column 0], 4, 3), every thing else below that will be assigned Partitionid = 2. Is that right?
Sergiy
Sergiy
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5848 Visits: 11407
You are missing column RowNo in your table Heap.
Files keep the data in physical order as they've been added to the file (because that's a definition of "file").
tables in relational databases do not have such a "natural" order of records.
You need to specify it and upload it from the file together with data.
UnionAll
UnionAll
SSC-Enthusiastic
SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)

Group: General Forum Members
Points: 194 Visits: 637
Sergiy (5/7/2013)
You are missing column RowNo in your table Heap.
Files keep the data in physical order as they've been added to the file (because that's a definition of "file").
tables in relational databases do not have such a "natural" order of records.
You need to specify it and upload it from the file together with data.


Thank you for this point. There is a row number in the file which I can import. It's a sequential incremental number for each record in the file, new partitions doesn't start with 1.

I'm still unable to write a query for this.
UnionAll
UnionAll
SSC-Enthusiastic
SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)SSC-Enthusiastic (194 reputation)

Group: General Forum Members
Points: 194 Visits: 637
Neeraj Dwivedi (5/7/2013)
What I can see from your result that, once you get 'Trl' from Substring([Column 0], 4, 3), every thing else below that will be assigned Partitionid = 2. Is that right?


Below the trailer record (we can get it by Substring([Column 0], 4, 3) = 'Trl') will be a new partition. But there can be more than two partitions, so yes, a new partition will start after the trailer record, but not everything else will be assigned Partition = 2.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search