Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

master detail insert sql server 2008

$
0
0

Friends...

I want to insert the data in to master and detail table....

i tried the below query...the master part is ok...its inserting...

but the detail part i am confused....not able to store the vocno...duplicate error..i dont know where i am making mistake.

declare @mastvocno int;

  insert into Student_Receipt(pre_vocdt,pre_cbcode,pre_customer,
  pre_amount,pre_narrat)  
  select getdate(),1001,
  rollnumber,feeamount,'Training Fee-2014'
  from student_demand
  where (RollNumber between 'A13MCC001' and 'A13MCC025')
  and (DueDate ='01-FEB-2014')
 
   
  SELECT @mastvocno=pre_vocno
FROM student_receipt
where (pre_customer between 'A13MCC001' and 'A13MCC025')
  and (CONVERT(VARCHAR(10), PRE_VOCDT , 103) ='01-02-2014')  
 
 
IF @mastvocno IS NULL
BEGIN
    RAISERROR('Voucher no. not found', 16, 0);
END
ELSE
BEGIN
    
  insert into Student_Receipt_detail(prd_vocno,prd_sno,prd_billno,prd_glcode,
  prd_amount,prd_period)  
  select @mastvocno , 1,demandno,feeglcode,
  feeamount,forsemester from student_demand
  where (RollNumber between 'A13MCC001' and 'A13MCC025')
  and (DueDate ='01-Feb-2014')
    
END;

thanks


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>