Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Return one rows from 2 tables

Author  Topic 

dave_kwok
Starting Member

1 Post

Posted - 2012-08-07 : 04:01:49
hi there,

Let said i have 2 table

E.g.
TableA
- Transactionno
- POno
- Invno
- Amount


TableB
- Transactionno
- POno
- text
- Amount

Data is like this

Table A

Transaction no | PONo | Invno | Amount
12345 | 54321| 33333 | 100

Table B

Transaction no | PONo | Text | Amount
12345 | 54321 |BANK123 | -100
12345 | 54321 |Supplier | 100


How can i get a return like below (Return only 1 row where the Amount in Table B = -100

Transaction no | PONo | Invno | Text | Amount
12345 | 54321| 33333 | BANK123 | 100

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-08-07 : 04:47:58
SELECT a.TransactionNO, a.PONo, a.Invno, b.Text, a.Amount
FROM TableA a INNER JOIN TableB b
WHERE a.TransactionNO = b.TransactionNO
AND b.Amount = -100

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-07 : 09:59:12
your sample output is contradicting with rule suggested. the explanation shows you need row with Amount=-100 and output shows the one with 100.
Will amount be always 100/-100? whats if there are multiple ones with amount as 100?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -