473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Sequence no group wise

Hi All,

I want to give sequence no group wise, as follows:

Section EmpCode
-----------------------
A 1001
A 1003
A 1009
B 1023
B 1030
C 1044
-----------------------

I want to set sequence no. group wise like this for above data.

Seq. Section EmpCode
------------------------------
1 A 1001
2 A 1003
3 A 1009
1 B 1023
2 B 1030
1 C 1044
----------------------------

Suggestion in this regard will be appreciated
Thanks in Advance,

T.S.Negi
Jul 23 '05 #1
3 1886
How about iterating through the table using a cursor, updating seq with
an iterative value, keeping track of section column.
Whenever the section coloumn changes value the iterator is reset to 1.

DECLARE cur CURSOR FOR SELECT select seq, section FROM your_table
ORDER BY 2 desc
OPEN cur

FETCH cur INTO @seq, @section
SET @iterator = 1
SET @prev = @section

WHILE @@FETCH_STATUS = 0
BEGIN
IF( @section <> @prev)
SET @iterator = 1

UPDATE your_table SET seq = @iterator

SET @iterator= @iterator + 1
SET @prev = @section
FETCH cur INTO @seq, @section
END

Jul 23 '05 #2
A little correction...it should be:

UPDATE your_table SET seq = @iterator WHERE CURRENT OF cur

and NOT:

UPDATE your_table SET seq = @iterator

Jul 23 '05 #3
On 13 Feb 2005 20:53:53 -0800, T.S.Negi wrote:
Hi All,

I want to give sequence no group wise, as follows:

Section EmpCode
-----------------------
A 1001
A 1003
A 1009
B 1023
B 1030
C 1044
-----------------------

I want to set sequence no. group wise like this for above data.

Seq. Section EmpCode
------------------------------
1 A 1001
2 A 1003
3 A 1009
1 B 1023
2 B 1030
1 C 1044
----------------------------

Suggestion in this regard will be appreciated


Hi T.S.,

SELECT COUNT(*) AS Seq,
a.Section,
a.EmpCode
FROM MyTable AS a
INNER JOIN MyTable AS b
ON b.Section = a.Section
AND b.EmpCode <= a.EmpCode
GROUP BY a.Section,
a.EmpCode

or

SELECT (SELECT COUNT(*)
FROM MyTable AS b
WHERE b.Section = a.Section
AND b.EmpCode <= a.EmpCode) AS Seq,
a.Section,
a.EmpCode
FROM MyTable AS a
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: python1 | last post by:
I apologize if this is redundant. How would one fill an empty column with a sequence of numbers? The column exists in a table with aproximately 1000000 rows of data. I believe in oracle the...
0
by: Anders Ljusberg | last post by:
Hi! I have a problem.. I'm trying to get the XML from a dataset to conform to an XSD, but it keeps rearranging some elements. Try this schema: &lt;xs:schema id="test"...
6
by: GSpiggle | last post by:
I have a database with records that should have a consecutive number ID (Check Register). Also has other records (deposits and adjusting entries) that don't fit in the number range so...
1
by: Ken | last post by:
I got an Access database that need to be converted to Oracle 9i. Somehow the Trigger we created to simulate the "AUTO NUMBER" on Access could not create the sequence number as soon as the value has...
3
by: Kyle Friesen via AccessMonster.com | last post by:
Mike, I have databse that creates a "tracking number" based on the selections made on the form via concatenating. At the end of the tracking number, I need a two digit (01-99) sequence number by...
3
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
43
by: Roger L. Cauvin | last post by:
Say I have some string that begins with an arbitrary sequence of characters and then alternates repeating the letters 'a' and 'b' any number of times, e.g. "xyz123aaabbaabbbbababbbbaaabb" I'm...
2
by: Eric Lilja | last post by:
I'm looking at an assignment where the students are expected to write a class with a given purpose. According to the assignment, you should be able to do this with instances of the class:...
2
by: RolfK | last post by:
Dear ALL, I need some help on xsl:sequence. I'm using the Altova XSLT processor, but I'm quite confident it is not an processor issue. It's probably my bad knowledge of xslt 2.0. I have probably...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.