Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table : TABLE A and TABLE B. The structure of both tables given below
TABLE A

DOCNO VENDOR
1 X
1
1
2 Y
2
2
3
3 Z
3

TABLE B
DOC VALUE
1 100
2 200
3 300
Here in both table DOCNO and DOC are primary Key. I need output using SQL query given below:
DOCNO VENDOR DOC VALUE
1 X 1 100
1 X 1 100
1 X 1 100
2 Y 2 200
2 Y 2 200
2 Y 2 200
3 Z 3 300
3 Z 3 300
3 Z 3 300

What I have tried:

select DOC_No,Vendor,DOC,
CASE when (a.Vendor <> '' and a.DOC_No = a.DOC) then
a.Vendor 
ELSE  '0'
end
from
(
select a.DOC_No , a.Vendor,b.Doc,b.Val from [dbo].[Vendor_Table]a
INNER JOIN [dbo].[Vendor]b ON a.DOC_No = b.DOC
) A
Posted
Updated 17-Oct-19 20:00pm

1 solution

You can use IS NOT NULL like this:
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
WHERE Customers.CustomerName IS NOT NULL;

SQL NULL Values - IS NULL and IS NOT NULL[^]
 
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