Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DECLARE @Installment_no VARCHAR(100) SELECT @Installment_no = Max(v.Installment_no) FROM Voucher_slip v,Loan l,Installments i,Customer c WHERE l.Loan_id=v.Loan_id and c.Loan_id=v.Loan_id and c.Customer_CNIC = '12345-1234567-8'; 

Select ins.Transaction_no  from Voucher_slip v,Loan l,Installments i,Customer c,Installment_Payment ins where l.Loan_id=v.Loan_id and c.Loan_id=v.Loan_id and l.Loan_id=ins.Loan_id and c.Customer_CNIC = '12345-1234567-8' and ins.Transaction_no=@Installment_no
Posted
Comments
[no name] 22-Feb-13 3:23am    
Please specify your problem more elaborately...
zeshanazam 22-Feb-13 4:36am    
i m getting installment no 10, but maximum installment no is 12
[no name] 22-Feb-13 4:58am    
Out of 12 instalments your condition might be satisfying only 10 thats why you are getting 10. Please check at your DB.
zeshanazam 22-Feb-13 5:06am    
i have checked everything carefully, but found nothing...
[no name] 22-Feb-13 5:16am    
Show me the results of the following queries separately.
1. Select ins.Transaction_no from Voucher_slip v,Loan l,Installments i,Customer c,Installment_Payment ins where l.Loan_id=v.Loan_id and c.Loan_id=v.Loan_id and l.Loan_id=ins.Loan_id and c.Customer_CNIC = '12345-1234567-8';

2. Select ins.Transaction_no from Voucher_slip v,Loan l,Installments i,Customer c,Installment_Payment ins where l.Loan_id=v.Loan_id and c.Loan_id=v.Loan_id and l.Loan_id=ins.Loan_id and c.Customer_CNIC = '12345-1234567-8' and ins.Transaction_no=@Installment_no

Hello friend,

If you want to select TOP 10 values from your table then use something like this...

SQL
Select TOP 10 ins.Transaction_no  from Voucher_slip v,
Loan l,
Installments i,
Customer c,
Installment_Payment ins 
where l.Loan_id=v.Loan_id 
and c.Loan_id=v.Loan_id 
and l.Loan_id=ins.Loan_id 
and c.Customer_CNIC = '12345-1234567-8' 
ORDER BY v.Installment_no DESC



If you want to select only one value from your table then use something like this...

SQL
Select TOP 1 ins.Transaction_no  from Voucher_slip v,
Loan l,
Installments i,
Customer c,
Installment_Payment ins
where l.Loan_id=v.Loan_id
and c.Loan_id=v.Loan_id
and l.Loan_id=ins.Loan_id
and c.Customer_CNIC = '12345-1234567-8'
ORDER BY v.Installment_no DESC
 
Share this answer
 
v2
Comments
zeshanazam 22-Feb-13 5:43am    
i want to select just maximum value
Tejas Vaishnav 22-Feb-13 6:00am    
Only one value which is max from all the data?
zeshanazam 22-Feb-13 7:50am    
yes
Hi Try this,


SQL
SELECT Transaction_no 
FROM Installment_Payment
WHERE Transaction_no IN( SELECT TOP 1 ins.Transaction_no  
				     FROM Voucher_slip v, Loan l, Installments i, Customer c, Installment_Payment ins
				     WHERE l.Loan_id=v.Loan_id
				     AND c.Loan_id=v.Loan_id
				     AND l.Loan_id=ins.Loan_id
				     AND c.Customer_CNIC = '12345-1234567-8'
				     ORDER BY v.Installment_no DESC)


Regards,
GVPrabu
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900