How to get top five rows in DataStage?

How to get top five rows in DataStage? I tried to use @INROWNUM,@OUTROWNUM system variables in transformer..but they are not giving unique sequential numbers for every row...please help!
Thanks in advance!!

Questions by naveen.chinthala   answers by naveen.chinthala

Showing Answers 1 - 37 of 37 Answers

MallikarjunaG

  • Jan 7th, 2013
 

The answer to this depends on the source from where you are trying to extract.

If the source in your case is a file, then we can use "Read first rows" property of Sequential file stage and specify 5 as the value.
Or use "Row number" property in the Sequential file stage and add a filter stage with a clause Rownumber < = 5
Or use "Filter" property in the Sequential file stage and specify the command "head -5" (without quotes)

If the source is a database like Oracle, use Rownumber pseudo column and specify rownum < 6 to get top 5 rows. Or you can use "TOP 5" clause if your source is sql server.

Or irrespective of source, use Head stage after the source stage and specify 5 for the number of rows to display.

jackie06

  • May 21st, 2013
 

Use stage variables and build a counter like
svCounter + 1 => svCounter
and then you build a condition to your output link svCounter = 5

  Was this answer useful?  Yes

Pradeep Kumar Bethina

  • Jul 1st, 2013
 

Use stage variables and build a counter like
svCounter + 1 => svCounter
and then you build a condition to your output link svCounter <= 5

  Was this answer useful?  Yes

GGGGGGG

  • Oct 26th, 2013
 

Using head Stage we can retrieve top 5 records

  Was this answer useful?  Yes

Kuldeep

  • Mar 12th, 2014
 

If you are using @inrownum and @outrownum then your output will vary from node by node. it is depend on what node (4 or 2 etc)your project is configured.

  Was this answer useful?  Yes

Bhavani

  • Aug 1st, 2014
 

It is very simple no need to think complex answers. In Seq file --> set property limit rows = 5. thats it..

  Was this answer useful?  Yes

Poorna

  • Aug 7th, 2014
 

You can restrict data it at source stage level its self @ using filter option.

Apply in filter : head -5

  Was this answer useful?  Yes

Vikram Singh

  • Nov 11th, 2014
 

You can use Head Stage, that would be the most convenient way of getting top N rows from the dataset.

  Was this answer useful?  Yes

lavanya

  • Apr 12th, 2016
 

You can use head stage instead

  Was this answer useful?  Yes

Ram

  • Apr 26th, 2016
 

You make sure to use single partition then you can use @INROWNUM , @OUTROWNUM system variable to get unique records of first top N.
Try it.
Thanks !

  Was this answer useful?  Yes

lalit

  • Oct 9th, 2017
 

If you want to use transformer only so you need to sort that data first....and after that you need to know how many no. of partitions you have in your transformer stage. Because @inrownum and @outrownum gives the sequence numbers as per the partition .....sort that data properly you can get the sequence properly as per the partion numbers by using system variables like @inrownum and @outrownum
Thank You

  Was this answer useful?  Yes

ravisankar

  • Sep 24th, 2018
 

Also you can get form sequential file (Read first row (5))

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions