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 2005 Forums
 Transact-SQL (2005)
 Joining uneven data

Author  Topic 

jocast
Starting Member

8 Posts

Posted - 2010-08-30 : 20:15:10
Hello forum
I have a problem. I have two tables

TableA
Ref | PN |Partqty | Price
AAA 123 10 12.00
AAA abc 8 15.00
AAA 023 11 8.00

Table B
Ref |setqty | type
AAA 2 Box
AAA 1 Pallet


I need this result
Ref | PN |Partqty | Price|setqty |type
AAA 123 10 12.00 2 Box
AAA abc 8 15.00 1 Pallet
AAA 023 11 8.00

Right now i am geting 9 rows each partnumber with each type.
Is there a way to do this???
Thank you

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-08-30 : 22:30:40
You would need to explain more. I don't understand the logic you have going to arrive at the output. Also, What do you mean by 'uneven data'?
Go to Top of Page

jocast
Starting Member

8 Posts

Posted - 2010-08-31 : 10:21:34
I mean that it will not fill all the part numbers with data i the setqty and type of box
Go to Top of Page

jocast
Starting Member

8 Posts

Posted - 2010-09-01 : 16:51:45
Anyone???
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-09-01 : 17:04:40
You need to change your query.


CODO ERGO SUM
Go to Top of Page

glendcruz
Yak Posting Veteran

60 Posts

Posted - 2010-09-01 : 20:10:05
I have been trying this out, but cannnot get anywhere. It lacks clarity. Could you explain it more clearly.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2010-09-01 : 22:09:14
Your explanation lacks clarity as well. How are you getting at setqty and type from table B and associating that with table A?
Go to Top of Page

PavanKK
Starting Member

32 Posts

Posted - 2010-09-02 : 04:29:22
Based on the displyed Data & required output, the following query is designed. I am not sure how it will help with your exact requirement.

As Saket said provide more details to help you better.


SELECT IDENTITY(INT,1,1) AS SNo,* INTO #TableA FROM TableA
SELECT IDENTITY(INT,1,1) AS SNo,* INTO #TableB FROM TableB

SELECT A.Ref,A.PN,A.Partqty,A.Price,B.setqty,B.type
FROM #TableA A
LEFT JOIN #TableB B ON A.SNo = B.SNo

DROP TABLE #TableA
DROP TABLE #TableB



KK
Go to Top of Page
   

- Advertisement -