0
ID  Name    Address Acc_Number  BookingNo   Amt
 1  MERY    Kollam  111111111   NULL        1000
 2  Jos     Kochi   111111111   c/01        NULL

output

ID  Name    Address Acc_Number  BookingNo   Amt
1   MERY    Kollam  111111111   c/01        1000
2
  • @user1581292- Name field of both rows will be different right? Commented Jan 2, 2013 at 4:55
  • ya ..its different want to take name in first row as MERY Commented Jan 2, 2013 at 4:57

2 Answers 2

2

I think self-joining to the same table using the Acc_Number should achieve that

SELECT 
     a.ID,  
     a.Name,    
     a.Address, 
     a.Acc_Number,  
     COALESCE(a.BookingNo, b.BookingNo) as BookingNo,   
     COALESCE(a.Amt, b.Amt) As Amt
FROM TableA a
JOIN TableA b
     ON a.Acc_Number = b.Acc_Number
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT top 1 t1.ID,t1.Name,  
     t1.Address, 
     t1.Acc_Number,  
     COALESCE(t1.BookingNo, t2.BookingNo) as 'BookingNo',COALESCE(t1.Amt, t2.Amt) as 'Amt'
FROM testtable1 t1 JOIN testtable1 t2 
     ON t1.Acc_Number = t2.Acc_Number and t1.NAME!=t2.NAME 

1 Comment

The way this written, the result returned could vary depending on the order in the table. If there is a specific ordering you want, you should use the order by operator which is applied before the top operator.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.