I have a table of form
CREATE TABLE [dbo].[table1](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[clientid] [int] NULL,
[startdate] [int] NULL,
[copyid] [int] NULL
)
data in the table is of form:
id clientid startdate copyid
1 4 11 1
2 4 12 1
3 4 44 2
3 5 123 1
4 5 15 1
5 5 12 2
6 5 12 2
7 5 12 2
the copyid is subset of clientid
My question is that can i form a select query which returns a table with N number of rows and is a copy of clientid and copyid combination with copyid incremented.
For e.g. it should if clientid is taken as 4 and copyid as 1 and N as 6 it should return 6 rows like
clientid startdate copyid
4 11 3
4 12 3
4 11 4
4 12 4
4 11 5
4 12 5
N will always be a multiple of client and copy combination
I know how to do this using loops. But is it possible using a single select query?