Filling column with Row Numbers
How to fill a column with row number in power query like below? is there any function in power query?
Color Row Number
Red 1
Green 2
Blue 3
Hi...
You can use "Add Index Column" function in Add column tab as below :
Table.AddIndexColumn(Source, "Row Number", 1, 1)
Regards,
Similar Messages
-
How to create a column with increasing numbers in h:dataTable?
I need to make a table that would have a column with order numbers, starting from 1 and increasing by 1 for every row. I tried using JSTL for this but it seems it is being ignored (as it probably should). My code is below. I know I am supposed to use getRowIndex() with bound tables, by my table isn't bound to anything...
I could hold the number in the backing bean but that seems like a total overkill.
Is there a proper way to this in JSF? Could I maybe somehow reference this (meaning tha table itself) within the EL expression?
<c:set var="month" value="0" />
<h:dataTable value="#{loansManager.rates}" var="rate">
<c:set var="month" value="${month+1}" />
<h:column>
<f:facet name="header">
<h:outputText value="Month" />
</f:facet>
<c:out value="${month}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Rate" />
</f:facet>
<h:outputText value="#{rate}" />
</h:column>
</h:dataTable>Bind the datatable to the backing bean and use HtmlDataTable#getRowIndex().
You can find here an example: [http://balusc.blogspot.com/2006/06/using-datatables.html#AddRowNumbers]. -
Add column with row number to table
Hi,
to a table view I'd like to add a new column that contains the row number for each row.
I have many data sources (twelve) and with the union operator I create one output dataset. The output data is sorted by the arrangement of the input ports of the union operator.
Is there a way to add a column with its corresponding entry number?
Regards, FTI have a similar question to the original post. It seems your answer will fill the new field in all rows with the same value. But, what if we want an actual row number?
I am simply looking to add a row number to a table. I only have one data source. The business scenario is that the output of the data service is sorted in descending order on value. I want to be able to select the first 10 (i.e. the top 10 items based on that value).
Even if I can solve my business scenario without using a row number field after the sort, it seems like a technique that would come in handy.
Any ideas? I'm pretty new to using Visual Composer so I may be missing something obvious. -
How do I print column letters/row numbers in Numbers?
In '08 someone asked about printing row numbers and column letters in a Numbers SS. The answer: take a snapshot (CMD-SFT-4) or use Excel.
I am using iWork09; the problem continues with it. Has this flaw been fixed in later versions of iWorks? When I print the spreadsheet and a formula sheet, the formula sheet is pretty worthless if the spreadsheet has no colum/row identifiers. So much for having someone else audit my formula work.lawrence5M wrote:
When I print the spreadsheet and a formula sheet, the formula sheet is pretty worthless if the spreadsheet has no colum/row identifiers. So much for having someone else audit my formula work.
Supply the auditor with a copy of the file, rather than a printed copy of the document. If she needs a printed copy of the formula list, that's easy to obtain from the file. When she clicks on a cell containing a formula, Numbers colour-codes the cell references and highlights the referenced cells with those colours.
Use Header Row and Header column cells to label each column and row. Set Numbers preferences to use these labels in the formulas to name the referenced cells.
Add a column to the left of the table to contain row numbers, and a row to the top to contain column letters. The row numbers are easy to generate with a simple formula; the column letters require a little more thought, especially for those past column 26 (Z, followed by AA), but it's doable.
Use the suggestion (auxiliary tables) suggested above by Wayne.
Two other suggestions:
First, if this feature is, in your estimation, a significant flaw in Numbers, send feedback to Apple requesting it be included in a future version of numbers. Use the Provide Numbers Feedback item in the Numbers menu, or the link in this message—both go to the same place.
Second, Use the application that best meets your needs, whichever application that turns out to be.
Regards,
Barry -
Alter a column with sequence numbers
Hi to all,
i have a table (sample) with cplumns: sno, sname,dob and so on..........
In this table i have milions of rows with random numbers in column sno
i want to give the give the sequence numbers from 1 to 10000 in the sno column to the begining rows in the table
(Oracle)
could u post the code plese
thanks & Regards
TangellaTangella wrote:
Hi to all,
i have a table (sample) with cplumns: sno, sname,dob and so on..........
In this table i have milions of rows with random numbers in column sno
i want to give the give the sequence numbers from 1 to 10000 in the sno column to the begining rows in the table
(Oracle)
could u post the code plese
thanks & Regards
TangellaHow do you define "the beginning rows in the table"? Rows in a relational, heap table have no "order" to them. There is no concept of "first".
And once that is defined, why would you want to assign sequence number to only 10k our of "millions" of rows? -
Using forms to fill columns not rows
Can I use a form to fill columns instead of rows? I have students names in a header column (each student is a different row) and I have assignments in different columns. Can I use a form and have the column info appear at the top with a list of students in the form to fill in grades for that assignment. The way it is now, it shows a single student at the top of the forum and all the assignments in the fill form. I want the opposite. I really don't want to create a column with a different student in each one. Too long of a table.
I did that for 2 hours last night and found out the sort doesn't work on the table with the references, so that meant on the form, nothing was sorted right (I have four fields I have to sort by depending on what I am doing). I tried creating a master table that I could sort, but the data table that the forms feed into won't sort. I ended up realizing that even though you can reference the cell of another sheet or table, it won't sort when the referred to table is sorted.
Example:
Master table
Bob (in cell A1)
John (in cell A2)
Adam (in cell A3)
Data Table
Bob (referrenced =A1)
John (referrenced =A2)
Adam (referrenced =A3)
Sort the Master Table:
Adam (in A1)
Bob (in A2)
John (in A3)
The data table does this:
Bob (referrenced =A2)
John (referrenced =A3)
Adam (referrenced =A1)
You can see the data table maintains it's original sort order regardless of how the master table is sorted. -
Populate columns with row values in Sql Server Reporting Services
I have got a dataset with 2 columns named Row and Title. There are 8 rows in this dataset and I want to display those 8 titles within columns in a table. So I create a table with 8 columns and set each column's expression to
=LookUp(Fields!Row.Value,1,Fields!Title.Value,"Titles")
=LookUp(Fields!Row.Value,2,Fields!Title.Value,"Titles")
=LookUp(Fields!Row.Value,3,Fields!Title.Value,"Titles")
However only the first column displays a title. The other 7 display nothing. Is my expression wrong?Hi,
Is the row datatype non-numeric? Maybe the lookup is failing for that reason. You coulr try adding a conversion to the field:
=LookUp(cint(Fields!Row.Value),1,Fields!Title.Value,"Titles")
Could you, perhaps, instead use a tablix table and put the Title column on the row group? That would pivot the data the way that you want it.
Mark -
Column with consecutive numbers in Numbers '09
Very simple question -- I did a search for this, but because my query involves the word "Numbers," it returned everything!
Okay, I have a list of 500 rows. I want to add a very simple column in Column A, that simply has "1" in Row 1, "2" in Row 2, all the way down to "500" in Row 500. If I type "1" into the first column, I can't seem to drag the cell down and do that -- it just inserts "1" into the entire column, which isn't what I want.
In other words, I want Column A to very simply look like this:
1
2
3
4
5
6
7
8
etc.
What's the right way to do that? Thanks.It probably is in the Numbers '09 User Guide, but if you don't know the answer, and haven't developed some good search techniques, it's one you might have trouble finding in the Guide.
John's subject line suggests he'd search using "consecutive" (zero occurrences), "number" (vast number of occurrences) or both words together (zero occurrences due to the absence of "consecutive").
"pattern" works, but I found that out by scanning Chapter 4, finding the paragraph that dealt with this, then using what appeared to be a potent word for a search. "You can also add values to cells based on value patterns" is the first line of a paragraph on page 76 (not 78, which deals with conditional formatting) of the English language edition of the guide.
I for one appreciate that John did a search, whether of the Guide or of this forum, before posting his question. That his search was unsuccessful is not really surprising; the information is moderately well hidden.
Regards,
Barry -
APEX Report - how can i create column with serial numbers in a report
Need help
I have created a report with displaying no of rows resticted to 43, every time i genarate this report i would like to add serial numbers from 6 to 48
apear in additional column. How can i do this?This is not really an APEX question, and would have been better posted on the {forum:id=75} forum.
Note also that the best way to get fast, effective answer to questions is to provide sufficient information for people to fully understand them:
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
You should also ensure that your forum profile is updated with a better handle than "user8308442".
Getting back to the question, one way to do this is using the analytic function ROW_NUMBER():
with t as (
-- Test data. Replace with actual query. ---------------------------------------
select
dbms_random.string('a', 10) query_data
from
dual
connect
by rownum <= 43)
select
5 + row_number() over (order by query_data) sn -- use required ordering here
, t.query_data
from
t
order by
sn
SN QUERY_DATA
6 CApoRenlch
7 CDiUiSYdMo
8 FsjsWFpTMT
9 KbbzXvYmQv
10 MrjEPqAzFs
11 QKOPSdVWpr
12 REIXjjdLtD
13 RijqpNTzmv
14 RngzthgaFv
15 SKcPxsdlBE
16 SuqFKzMqbB
17 TxlglIYENC
18 TyWlxKbDIg
19 VdRbUOUOPz
20 XIQxzkBuKY
21 YVcWUJrswt
22 aVoYNlMkfx
23 cHZPsOlzYM
24 cTUEztIOae
25 etdNGqQasP
26 fVGoGWmdLL
27 gHANXpbvMW
28 gRNBnwtEhO
29 iyefgszgLT
30 jRaliUJjKS
31 jpzAvQXBwY
32 kJifAaetUN
33 kfbTWGGCpR
34 mTPtqYGvrG
35 mhAPgdzezZ
36 pdXidmikRX
37 pwNdAsqpIV
38 rPTBTObdKg
39 sFoNLHLeMH
40 squTbOYVUM
41 tPxSMqPpnQ
42 uJtqCybjXB
43 vEvrwnGnyJ
44 xOOseicRRy
45 xqqXBKURog
46 ydOPurqyvo
47 yqEZvoNsbg
48 zsWFLHjVLK
43 rows selected -
Is there any easy way to show row numbers in JTable?
Just like in Excel.
I think the easiest way would be to make your first column the row numbers, then make your own cell renderer for the first column that renders the text in like, a JLabel with a gray background and a raised bevel border or something. You could even go sofar as to write a new selection model that selects an entire row when you select a cell in the first column. Getting the row number is easy enough, as the row and column number are both passed to the getValueAt() method of the table data model.
Jason -
Pre populate field with integer numbers?
Hi,
I want to pre-populate my field which is integer type with numbers in a sequantial order like 101,102,103,104...
How can i do this with 10gr2?
Regards.Actually i have two tables.
First table has ID1, NAME1, REF1 columns.
Second table has ID2, NAME2, REF2 columns.
ID1 and ID2 is autonumbered id columns. NAME and REF columns are emtpy columns. I populated NAME1 and NAME2 manually entering data from my project.
Now i want to relate each table's rows one by one, i.e., one to one cardinality. Therefore, i have to populate first table's REF1 column with sequantial numbers, and then manually enter corresponding number to table two's REF2 columns.
I don't want to use ID columns, because i insert data these tables at different time intervals.
Hence, when i query TABLE1's NAME1 data, i will see corresponding data in TABLE2's NAME2 column via this relationship. -
Merging two columns with muliple rows in Numbers '09
I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
Ed Carreonsanpanza wrote:
I am trying to merge two columns each with 100 rows and related data. Column one is the street address and column two have office numbers. The final result would be one column with 100 rows with address and office numbers.
Ed Carreon
Hi Ed,
Use the CONCATENATE() function.
Street address in column D, Office number in Column E
100 Smith ST 212
Formula: =CONCATENATE(E," ",D)
Result:
212 100 Smith ST
Note the formula has three arguments, the reference to column E, a text literal (" ") containing a single space, and a reference to column D.
Regards,
Barry -
Tables with differing numbers of columns in subsequent rows
I'm trying to create a table that has say 3 columns in row one, 2 columns in row two, 5 columns in row 5. I've done it so far by merging cells and splitting them and then asking it to distribute columns evenly but the columns are not distributed evenly.
The column width button is greyed out so I can't set the width manually and so my table looks really unprofessional.
Is there a better way of creating such a table and getting equally distributed columns?
Many thanks
sekentiousan example of merging cells is here
[http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples4.html]
scroll down to 'Multi-Span Cell'
run the program, highlight some cells, click combine.
if that's the type of thing you're after, modify your code per what's in 'combine'
note: the original code (now) produces a stack overflow error (don't know if it's been fixed in the above link),
but if you get that error, in AttributiveCellTableModel's setDataVector( Vector newData, Vector columnNames )
change
setColumnIdentifiers(columnNames);
to
columnIdentifiers = columnNames; -
Print Row Numbers and Column Letters
How do you tell Numbers to print the Row numbers and Column letters? This was very simple in Appleworks (print dialog box had that option). Can't find it in Numbers though.
Here is a script doing all the job for us.
Just select one or several cells in a table and run the script.
It duplicates it, add an header row, an header column, insert the needed labels and fill the other cells with a formula grabbing the contents of the original table.
--[SCRIPT build a table with headers]
Enregistrer len tant que Script: build a table with headers.scpt
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Selectionner une cellule dans la table à dupliquer
menu Scripts > Numbers > build a table with headers
Le script duplique la table et crée des en-têtes de lignes et colonnes.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
+++++++
Save the script as Script: build a table with headers.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Select a range of cells in the table to 'duplicate'
menu Scripts > Numbers > build a table with headers
The script duplicate the table and inserts columns/rows headers.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
--=====
Yvan KOENIG (VALLAURIS, France)
2009/09/19
--=====
property theApp : "Numbers"
--=====
my activateGUIscripting() (* to be sure than GUI scripting will be active *)
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if
set new_Table to t_Name & "_#"
my duplicateTable(s_Name, t_Name, new_Table)
set delim to my getLocalizedDelimiter()
(* grab localized function names and add an open parenthesis at end *)
set IF_loc to my getLocalizedFunctionName("Numbers", "IF") & "("
set CHAR_loc to my getLocalizedFunctionName("Numbers", "CHAR") & "("
set INT_loc to my getLocalizedFunctionName("Numbers", "INT") & "("
set MOD_loc to my getLocalizedFunctionName("Numbers", "MOD") & "("
set INDIRECT_loc to my getLocalizedFunctionName("Numbers", "INDIRECT") & "("
set ADDRESS_loc to my getLocalizedFunctionName("Numbers", "ADDRESS") & "("
(* grab localized function names and add a couple of parenthesis at end *)
set ROW_loc to my getLocalizedFunctionName("Numbers", "ROW") & "()"
set COLUMN_loc to my getLocalizedFunctionName("Numbers", "COLUMN") & "()"
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table new_Table
if column count = 256 then
if my parleAnglais() then
error "Oops, already 256 columns !"
else
error "Désolé, il y a déjà 256 colonnes !"
end if
end if
if row count = 65536 then
if my parleAnglais() then
error "Oops, already 65536 rows !"
else
error "Désolé, il y a déjà 65536 lignes !"
end if
end if
try
add row above row 1
on error
if my parleAnglais() then
error "Oops, already five header row !"
else
error "Désolé, il y a déjà cinq rangs d’en tête !"
end if
end try
try
add column before column 1
on error
if my parleAnglais() then
error "Oops, already five header columns !"
else
error "Désolé, il y a déjà cinq rangs d’en tête !"
end if
end try
set nbr to row count
set nbc to column count
(* =IF(COLUMN()<28,CHAR(COLUMN()63),CHAR(INT((COLUMN()-2)/26)+64)&CHAR(MOD(COLUMN()-2,26)65)) *)
set theFormula to "=" & IF_loc & COLUMN_loc & "<28" & delim & CHAR_loc & COLUMN_loc & "+63)" & delim & CHAR_loc & INT_loc & "(" & COLUMN_loc & "-2)/26)+64)&" & CHAR_loc & MOD_loc & COLUMN_loc & "-2" & delim & "26)+65))"
tell row 1
repeat with c from 2 to nbc
set value of cell c to theFormula
end repeat
end tell -- row 1
(* =ROW()-1 *)
set theFormula to "=" & ROW_loc & "-1"
tell column 1
repeat with r from 2 to nbr
set value of cell r to theFormula
end repeat
end tell -- column 1
(* =INDIRECT(ADDRESS(ROW()-1,COLUMN()-1,,,"Tableau 2")) *)
set theFormula to "=" & INDIRECT_loc & ADDRESS_loc & ROW_loc & "-1" & delim & COLUMN_loc & "-1" & delim & delim & delim & quote & t_Name & quote & "))"
repeat with r from 2 to nbr
repeat with c from 2 to nbc
set value of cell r of column c to theFormula
end repeat -- with c
end repeat -- with r
end tell -- Numbers
--=====
Set the parameter delimiter which must be used in Numbers formulas
on getLocalizedDelimiter()
if character 2 of (0.5 as text) is "." then
return ","
else
return ";"
end if
end getLocalizedDelimiter
--=====
on getLocalizedFunctionName(theApp, x)
local p2bndl
set p2bndl to (path to application support as text) & "iWork '09:Frameworks:SFTabular.framework:Versions:A:Resources:"
return my getLocalizedName(theApp, x, p2bndl)
end getLocalizedFunctionName
--=====
on getLocalizedName(a, x, f)
tell application a to return localized string x from table "Localizable" in bundle file f
end getLocalizedName
--=====
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theDoc, theSheet, theTable, theRange}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on isItAsheet(s)
try
tell application "Numbers" to tell document 1
count of tables of sheet s (*
Post an error if s is not a sheet *)
end tell
return true
on error
return false
end try
end isItAsheet
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
on duplicateTable(sourceSheet, sourceTable, newName)
local lesFeuilles, lesTables1, found, listOfRows, cor, i, isSourceSheet, nameI, j, lesTables2
tell application "Numbers"
activate
tell document 1
set lesFeuilles to name of sheets
if sourceSheet is in lesFeuilles then
tell sheet sourceSheet to set lesTables1 to name of tables
if sourceTable is not in lesTables1 then
if my parleAnglais() then
error "The sheet “" & sourceTable & "” of sheet “" & sourceSheet & "” is unavailable ! "
else
error "La table “" & sourceTable & "” de la feuille “" & sourceSheet & "” n'existe pas ! "
end if
end if -- sourceTable is not
else
if my parleAnglais() then
error "The sheet “" & sourceSheet & "” is unavailable ! "
else
error "La feuille “" & sourceSheet & "” n'existe pas ! "
end if
end if -- sourceSheet is in
end tell -- document
end tell -- application
if newName is not in lesTables1 then (*
Now, an ugly workaround to duplicate the sheet *)
set isOS4 to (system attribute "sys2") < 5
tell application "System Events" to tell application process "Numbers"
set docWindow to false (* CAUTION, an inspector ("AXFloatingWindow") or a Find/Search ("AXDialog") window may be open *)
repeat with i from 1 to (count of windows)
if subrole of window i is "AXStandardWindow" then
set docWindow to i (* got the document's window *)
exit repeat
end if
end repeat
if docWindow is not false then
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window docWindow
select row 1
set value of attribute "AXFocused" to true
set found to false
set listOfRows to name of static text of every row
set cor to count of rows (* equal count of listOfRows *)
if isOS4 then (*
for mac Os X 10.4.11
CAUTION, listOfRows it's a list of lists !
{{"Feuille 2"}, {"Tableau 1"}, {"theSheet"}, {"Feuille 1"}, {"Tableau 2"}, {"Clément"}, {"Feuille 4"}} *)
repeat with i from 1 to cor (*
Scan the thumbnails *)
set nameI to item 1 of item i of listOfRows
set isSourceSheet to (sourceSheet = nameI) and my isItAsheet(nameI)
if isSourceSheet then
select row i
if (i < cor) and not my isItAsheet(item 1 of item (i + 1) of listOfRows) then (*
Here we may scan the thumbnails of tables of sourceSheet *)
repeat with j from i + 1 to i + (count of lesTables1)
if sourceTable = item 1 of item j of listOfRows then
select row j
set found to true
exit repeat
end if -- sourceTable
end repeat
else
if my parleAnglais() then
error "The sheet “" & sourceTable & "” of sheet “" & sourceSheet & "”" & return & " is not revealed in thumbnails ! "
else
error "La table “" & sourceTable & "” de la feuille “" & sourceSheet & "”" & return & " n'est pas affichée dans les vignettes ! "
end if -- my parleFrancais
end if -- (i < cor)
end if -- isSourceSheet
if found then exit repeat
end repeat -- i
else (*
for mac Os X 10.5.x
CAUTION, listOfRows is a list of lists !
{{}, {"Tableau 1"}, {"theSheet"}, {}, {"Tableau 2"}, {"Clément"}, {}}
With 10.5.x, the names of sheets are empty *)
repeat with i from 1 to cor
set isSourceSheet to (class of UI element 1 of row i is group) and (get value of static text 1 of group 1 of row i) is sourceSheet
if isSourceSheet then (*
Here we may scan the thumbnails of tables of sourceSheet *)
if value of UI element 1 of group 1 of row i is 0 then (*
reveal the tables's thumbnails and adjust the list accordingly *)
click UI element 1 of group 1 of row i (* click the black triangle to reveal tables *)
delay 0.1
set listOfRows to name of static text of every row (* update the list accordingly *)
end if -- value of UI…
repeat with j from i + 1 to i + (count of lesTables1)
if sourceTable = item 1 of item j of listOfRows then
select row j
set found to true
exit repeat
end if -- sourcetable
end repeat -- with j
end if -- isSourceSheet
if found then exit repeat
end repeat -- with i
end if -- check OS
end tell -- outline …
keystroke "d" using command down
end if -- docWindow
end tell -- System Events…
if docWindow is not false then (*
Rename the new table according to the passed name: newTable *)
tell application "Numbers" to tell document 1 to tell sheet sourceSheet
set lesTables2 to name of tables
repeat with i in lesTables2
if i is not in lesTables1 then (*
Here i is the name of the newly created table *)
set name of table i to newName
exit repeat
end if
end repeat
end tell
end if -- docWindow
end if -- newName is not…
end duplicateTable
--=====
on parleAnglais()
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
Yvan KOENIG (VALLAURIS, France) samedi 19 septembre 2009 17:33:59 -
Fill a column with serial number
Hello, all seniors..!
my table has one empty tno (number) column, that i now wish to fill it with a series of numbers
for as many records that are present.
the sample table data is; 1 SELECT TXN_DATE
2 FROM PTXN
3* WHERE ROWNUM <10
TXN_DATE
18/03/2010
02/02/2010
10/02/2010
05/04/2010
15/05/2010
25/01/2010
03/02/2010
15/01/2010
25/04/2010
9 rows selected.
I issue this command;
update ptxn
set tno = rownum
With the above Update SQL, the TNO column got filled with the exact number of records. Like this,
SELECT TXN_DATE,tno
FROM PTXN;
TXN_DATE TNO
03/02/2010 1
15/01/2010 2
02/02/2010 4
25/04/2010 8
25/01/2010 3
18/03/2010 6
15/05/2010 9
10/02/2010 5
05/04/2010 7
9 rows selected.
what i actually want is to sort my table (ptxn) by column 'txn_date' wise and then fill series.
Like this;
TXN_DATE TNO
15/01/2010 1
25/01/2010 2
02/02/2010 4
03/02/2010 8
10/02/2010 3
18/03/2010 6
05/04/2010 9
25/04/2010 5
15/05/2010 7
How do i modify my Update statement ot any other solution, please suggest.Using PL/SQL:
SQL> select * from PTXN ;
TXN_DATE TNO
07-MAR-10
26-FEB-10
01-MAR-10
08-FEB-10
03-MAR-10
16-APR-10
11-APR-10
08-MAY-10
14-MAR-10
18-APR-10
10 rows selected.
SQL> begin
2 for r in (select rowid i, TXN_DATE, row_number() over (order by TXN_DATE) n from PTXN) loop
3 UPDATE PTXN p
4 set TNO = r.n
5 where rowid = r.i;
6 end loop;
7 end;
8 /
PL/SQL procedure successfully completed.
SQL> select * from PTXN
2 order by 1;
TXN_DATE TNO
08-FEB-10 1
26-FEB-10 2
01-MAR-10 3
03-MAR-10 4
07-MAR-10 5
14-MAR-10 6
11-APR-10 7
16-APR-10 8
18-APR-10 9
08-MAY-10 10
10 rows selected.Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/01/31/le-direttive-di-compilazione-pragma/]
Maybe you are looking for
-
Issue with printing of multiple text elements in main window
Hi experts, I have developed a sales order form in SAP script. I hv got two text elements in the main window. n i m calling these two text elements by using two write form functions in d print program. The first text element is gettin called n d rele
-
Change background in Adobe Bridge Web Gallery
Hi, I am trying to use a web gallery created with adobe bridge in my webpage. I have inserted gallery in an <iframe>. The gallery shows up just fine. I would like to have the background of the webpage show up rather than the background of the web g
-
Buttons interfering with animation
I am modifying a Flash 8 movie. The fla can be downloaded here: www.cjreynolds.com/fuda.html There is a movie clip in the fla called "page1" with a text box with six menu items (Fuda Sushi, Fuda Maki, etc.). When the swf is run, each item has a carat
-
Hi, can any body tell me how to input new field in sapsript without changing standard sap program. e.t.c to change user on invoice report.
-
Hi all. I need to create a Ztable ,it has 2 key fields and 2 index fields. what is the use of index fields ? how is it diff from key fields? how can i create index for my Ztable? To be reward all helpfull answer. JNJ