Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends, i have Table OpeningBalance and fields are
C#
TrnsNo  CustomerName
  1        Kiran
  2        Nagappa
  3        prasanth
  4        kiran

Now i want to select customer name kiran and with its maximum TrnsNO
Posted
Updated 31-Oct-13 23:02pm
v2

 
Share this answer
 
Comments
CHill60 2-Nov-13 10:56am    
Good link. My 5
SQL
Select max(TrnsNo) from OpeningBalance where CustomerName='Kiran'
 
Share this answer
 
Comments
CHill60 2-Nov-13 10:57am    
My 5 as this does exactly what the OP asked for (but no more).
SQL
SELECT *
FROM OpeningsBalance
WHERE TrnsNo in(select TrnsNo from OpeningsBalance where Customername='TESTT');
 
Share this answer
 
Comments
CHill60 2-Nov-13 10:55am    
Reason for my downvote ... OP requires maximum TrnsNo and Customername = 'Kiran', and the structure of your SQL is poor and inefficient. If you have two customers with a TrnsNo of say '5' then you will get the data for both customers instead of just TESTT.
murkalkiran 5-Nov-13 0:13am    
The Same trnsNo will not repeat because its auto generate no
CHill60 5-Nov-13 11:35am    
Fair enough - although that wasn't mentioned. However your SQL could therefore be simplified to SELECT * FROM OpeningsBalance Where Customername = 'TESTT' which still does not fit the requirement. SELECT TOP 1 * FROM OpeningsBalance Where Customername = 'kiran' ORDER BY TrnsNo would be tidier
murkalkiran 6-Nov-13 0:55am    
Ya CHill60 its also working fine thanks

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