After correcting the name of the table on your second insert and adding a couple of SELECT statements, I get these results:
SELECT * FROM dbo.Receipt;
SELECT * FROM dbo.MemberPremiumDet;
ReceiptID PolicyID ReceiptAmt
1 11 3000.00
2 11 5000.00
3 11 1200.00
MemberID PolicyID PremiumAmt
1 11 1200.00
2 11 1600.00
3 11 2200.00
4 11 2456.00
5 11 1144.00
Perhaps you'd explain where MemberIDs of 171-175 and ReceiptIDs of 11, 14 and 16 come from in your expected results?:
Since you're in a hurry and all.
uravindarreddy (6/20/2013)
Hi SQL Addicts,I Want the output as follows
MemberIDReceiptIDReceiptAmtConsumedAmtBALAmt
17111300012001800
1721118001600200
173112002000
17314500020003000
1741430002456544
175145445440
175161200600600
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St