Hi
Create table test3
(
Id int primary key identity(1,1),
No_of_test3 int,
Name varchar(50),
)
Create table test4
(
test4id int primary key identity(1,1),
test4Name varchar(50),
test3id int foreign key references test3(id)
)
I want to Insert value into Test4 on the basis of test3
In Table test3 No_of_test3 int is 5 then i want 5 rows in test 4

Manas MohapatraPosted Aug 4, 2015, 2:29 AM
Amitesh VermaPosted Aug 4, 2015, 2:37 AM
create table #temp2 (id int identity(1,1),name varchar(20))
insert into #temp2 values('A10,B20,C34')
insert into #temp2 values('A11,B21,C31')
insert into #temp2 values('A12,B22,C32')
drop table #temp1
create table #temp1 (col1 varchar(3))
insert into #temp1 values('AA')
insert into #temp1 values('AA1')
insert into #temp1 values('AA2')
insert into #temp1 values('AA3')
declare @rowcounttable1 int,@rowcounttable2 int
select @rowcounttable2=COUNT(*) from #temp2
select @rowcounttable1=COUNT(*) from #temp1
select @rowcounttable1
select @rowcounttable2
--while(@rowcounttable2>@rowcounttable1)
while (@rowcounttable2<@rowcounttable1)
begin
set @rowcounttable1=@rowcounttable1-1
select @rowcounttable1
select @rowcounttable2
insert into #temp1 values('AA4')
end
select * from #temp1