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
 General SQL Server Forums
 New to SQL Server Programming
 I need SQL statement that satisfies this output.

Author  Topic 

bdaijinx123
Starting Member

1 Post

Posted - 2011-02-08 : 18:32:05
Ok I am going thru this for a week now and I cant seem to figure it out.
I have this 3 tables that has relationship to one another. I need to output a query/queries to merge them following a specific layout.

INVENTORY_STOCK

DESC PART_NUMBER EXP_AMT ID

PART1 AAAAA111111 96 1
PART2 BBBBB111111 6 2
PART3 CCCCC111111 6 3
PART4 DDDDD111111 2 4


INCOMING_STOCK

SI PART_NUMBER ARRV_AMT ID

1234 AAAAA111111 96 3
123 BBBBB111111 6 4
1234 CCCCC111111 6 2
1234 DDDDD111111 2 1


STOCK_DISTRIBUTION

SITE_# PART_NUMBER AMT ID

SITE1 AAAAA111111 2 13
SITE2 AAAAA111111 16 10
SITE3 AAAAA111111 32 9
SITE4 AAAAA111111 16 6
SITE5 AAAAA111111 16 8
SITE6 BBBBB111111 2 12
SITE7 CCCCC111111 1 11
SITE8 CCCCC111111 1 7
SITE9 CCCCC111111 1 5
SITE10 CCCCC111111 1 4
SITE11 CCCCC111111 1 3
SITE12 CCCCC111111 1 2
SITE13 DDDDD111111 2 1


OUTPUT_SUMMARY

DESC PART_NUMBER EXP_AMT 123 1234..SO ON SITE1 SITE2 ..SO ON

PART1 AAAAA111111 96 0 96 ..SO ON 2 16 ..SO ON
PART2 BBBBB111111 6 6 0 ..SO ON 0 0 ..SO ON
PART3 CCCCC111111 6 0 6 ..SO ON 0 0 ..SO ON
PART4 DDDDD111111 2 0 2 ..SO ON 0 0 ..SO ON


OK. I want that output to show in a merged table from 3 tables.
I dont know how can I merge them all without conflicts also I dont have enough knowledge to transfer rows to become column names. Please help

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-08 : 18:36:29
Can you follow this for posting the data? OTherwise we have to do a lot of guessing.

What have you tried so far?

For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx




Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-02-09 : 05:01:16
Read up on Madhis dynamic pivot:

http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

- Lumbago
My blog-> www.thefirstsql.com
Go to Top of Page
   

- Advertisement -