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.
| Author |
Topic |
|
sqluser78
Starting Member
1 Post |
Posted - 2011-04-21 : 05:44:38
|
| dear all,sql server verison is 2000following is data structure and sample datacreate table temp (s_no int, ref as varchar(10), counter smallint)insert into temp values(1,'12305',4)insert into temp values(2,'65509',3)insert into temp values(3,'98601',1)insert into temp values(4,'97607',5)insert into temp values(5,'52205',2)i want following outputs_no ref ref_counter1 12305 123051 12305 123061 12305 123071 12305 123081 12305 123092 65509 655092 65509 655102 65509 655113 98601 986014 97607 976074 97607 976084 97607 976094 97607 976104 97607 976115 52205 522055 52205 52206here counter can be from 1 to 99and in out put i have to add this couter values to produce the desired result how it can be possiblesqluser |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2011-04-21 : 06:42:31
|
Use a number/tally table.The following uses master.dbo.spt_values but it would be better to have a tally table in your db.SELECT T.s_no, T.ref, T.ref + N.number AS ref_counterFROM [temp] TJOIN master.dbo.spt_values NON N.type = 'P' AND N.number < T.counter |
 |
|
|
|
|
|
|
|