September 7, 2010 at 10:20 am
Hi everyone,
I having a table Tran_Id in that table two columns Id and Sno.
ID SNO
1 5124
2 6231
if i selected a particular Id's and Sno means i need the result like the below format
ID SNo
1 5124
1 5125
1 5126
1 5127
: :
: :
1 5133
Suppose i select the ID= 2 means I need SNo started from 6231 to 6240
Any help would be appreciated. Thanks in advance.
September 7, 2010 at 10:35 am
I would use CROSS APPLY on a 10 row table (or subquery):
DECLARE @t TABLE(ID INT, SNO INT)
INSERT INTO @t
SELECT 1,5124 UNION ALL
SELECT 2,6231
SELECT t.ID , t.SNO + z.N
FROM @t t
CROSS APPLY
(
SELECT number N from master..spt_values WHERE type='P' and number<10
)z
ORDER BY t.ID,N
September 7, 2010 at 11:44 am
shankaran_sraj (9/7/2010)
Hi everyone,I having a table Tran_Id in that table two columns Id and Sno.
ID SNO
1 5124
2 6231
if i selected a particular Id's and Sno means i need the result like the below format
ID SNo
1 5124
1 5125
1 5126
1 5127
: :
: :
1 5133
Suppose i select the ID= 2 means I need SNo started from 6231 to 6240
Any help would be appreciated. Thanks in advance.
What do you want to do if one of those calculated numbers already exists in the table?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply