Wednesday, March 7, 2012
Help to write a query to kamal
hello,
I have a Question Paper table
Create Table QPaper (QPID, QPName,SubjectSLNo,Type, NoOfQues)
Data is like
Insert Into QPaper Values (1, 'UNIT1', 1,'Objective', 10)
Insert Into QPaper Values (2, 'UNIT1', 1,'Descriptive', 5)
Insert Into QPaper Values (3, 'UNIT2', 1,'Objective', 2)
Insert Into QPaper Values (4, 'UNIT2', 1,'Objective', 15)
My Output should be
1, 'UNIT1', 1,'Objective', 1, 1
1, 'UNIT1', 1,'Objective', 1, 2
1, 'UNIT1', 1,'Objective', 1, 3
1, 'UNIT1', 1,'Objective', 1, 4
--
--
--
1, 'UNIT1', 1,'Objective', 1, 10
2, 'UNIT1', 1,'Descriptive', 5,1
2, 'UNIT1', 1,'Descriptive', 5,2
--
--
--
2, 'UNIT1', 1,'Descriptive', 5,5
3, 'UNIT2', 1,'Objective', 2,1
3, 'UNIT2', 1,'Objective', 2,2
4, 'UNIT2', 1,'Objective', 15,1
4, 'UNIT2', 1,'Objective', 15,2
4, 'UNIT2', 1,'Objective', 15,3
--
--
--
--
--
4, 'UNIT2', 1,'Objective', 15,15
thanks on advance
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Try,
use northwind
go
select
identity(int, 1, 1) as number
into
number
from
sysobjects as a cross join sysobjects as b
go
Create Table QPaper (QPID int, QPName varchar(25) ,SubjectSLNo int,Type
varchar(25), NoOfQues int)
go
Insert Into QPaper Values (1, 'UNIT1', 1,'Objective', 10)
Insert Into QPaper Values (2, 'UNIT1', 1,'Descriptive', 5)
Insert Into QPaper Values (3, 'UNIT2', 1,'Objective', 2)
Insert Into QPaper Values (4, 'UNIT2', 1,'Objective', 15)
go
select
a.QPID,
a.QPName,
a.SubjectSLNo,
a.Type,
a.NoOfQues,
n.number
from
QPaper as a
inner join
number as n
on n.number <= a.NoOfQues
order by
a.QPID,
n.number
go
drop Table QPaper, number
go
AMB
"kamal hussain" wrote:
>
> hello,
> I have a Question Paper table
> Create Table QPaper (QPID, QPName,SubjectSLNo,Type, NoOfQues)
> Data is like
> Insert Into QPaper Values (1, 'UNIT1', 1,'Objective', 10)
> Insert Into QPaper Values (2, 'UNIT1', 1,'Descriptive', 5)
> Insert Into QPaper Values (3, 'UNIT2', 1,'Objective', 2)
> Insert Into QPaper Values (4, 'UNIT2', 1,'Objective', 15)
> My Output should be
> 1, 'UNIT1', 1,'Objective', 1, 1
> 1, 'UNIT1', 1,'Objective', 1, 2
> 1, 'UNIT1', 1,'Objective', 1, 3
> 1, 'UNIT1', 1,'Objective', 1, 4
> --
> --
> --
> 1, 'UNIT1', 1,'Objective', 1, 10
> 2, 'UNIT1', 1,'Descriptive', 5,1
> 2, 'UNIT1', 1,'Descriptive', 5,2
> --
> --
> --
> 2, 'UNIT1', 1,'Descriptive', 5,5
> 3, 'UNIT2', 1,'Objective', 2,1
> 3, 'UNIT2', 1,'Objective', 2,2
> 4, 'UNIT2', 1,'Objective', 15,1
> 4, 'UNIT2', 1,'Objective', 15,2
> 4, 'UNIT2', 1,'Objective', 15,3
> --
> --
> --
> --
> --
> 4, 'UNIT2', 1,'Objective', 15,15
>
> thanks on advance
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment