473,664 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1901
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
8719
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 following would work: update foo set bar = rownum; ....but 'rownum' does not seem to exist in mssql. The numbers do not need to be in order, but I would like to keep them somewhat small.
0
1271
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" targetNamespace="http://tempuri.org/test.xsd"
6
4614
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 autonumbering isn't the answer. I want to check to see if any check numbers are missing from the register, but can't figure out how to accomplish it. Thanks for any help.
1
454
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 been inserted. The sequence number can only be created after we go to the second line. Please see the trigger below. Is there anyway we could create a trigger that could create the sequence number as soon as we enter a value? It should be...
3
2810
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 product group for each customer. Hpw do I do this without creating a table for each customer and each product group with autonumbers. For example based on the entries in this sample, the desired result would be: Customer Business Unit Tracking...
3
4717
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 to not be sequenced. (PERL hashes do not retain order information) First, the w3 specs don't mention the sequence in any detail - its just there in the examples, which makes me wonder if removing the sequence tag is even supportable. Second,...
43
2794
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 looking for a regular expression that matches the first, and only the first, sequence of the letter 'a', and only if the length of the sequence is exactly 3.
2
2120
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: ++instance_of_class; instance_of_class++; (++instance_of_class)++; // Isn't this invalid C++? but not: ++(instance_of_class++);
2
2621
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 put more that required in the test case, but it basically covers my more complex code. Here is the xml example source: <?xml version="1.0" encoding="UTF-8"?> <SeqTest>
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.