Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sql data manipulation

Author  Topic 

jay_sql
Starting Member

3 Posts

Posted - 2009-01-31 : 17:50:54
I got a table named tblAlerts. It has two columns viz., ALERTS, ROW_TEXT and has many rows in the table. The sample of few rows is shown below

ALERTS ROW_TEXT
------- --------
1010748 Yes
1010748 No
1010748 N/A
1010749 Yes
1010749 No
1010749 N/A
1010751 Yes
1010752 Yes
1010752 No
1010752 N/A
1010753 Yes
1010754 Yes
1010754 No
1010754 N/A
1010755 Not OK
1010755 N/A
1010757 11111
1010757 22222
1010757 33333


Now, I need to do sql manipulation and produce the table as below with three columns viz., ALERTS, ROW_TEXT and ROW_ID. Basically ROW_ID is evolved from ALERTS and it is just a sequence number relevant to ALERTS. As ALERTS 1010748 has three rows, so in the ROW_ID you have numbers 1,2,3.... similarly for ALERTS 1010753 has only one row, thus the ROW_ID has 1. For ALERTS 1010754 has four rows, thus the ROW_ID has 1,2,3,4.

ALERTS ROW_TEXT ROW_ID
----------- -------------- ----------
1010748 Yes 1
1010748 No 2
1010748 N/A 3
1010749 Yes 1
1010749 No 2
1010749 N/A 3
1010751 Yes 1
1010752 Yes 1
1010752 No 2
1010752 N/A 3
1010753 Yes 1
1010754 Yes 1
1010754 No 2
1010754 N/A 3
1010754 None 4
1010755 Not OK 1
1010755 N/A 2
1010757 11111 1
1010757 22222 2
1010757 33333 3

Thanks,
Jay

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-01-31 : 18:35:27
crosspost
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=118972


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-31 : 18:47:06
Duplicate, locking thread.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -