SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Join Statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Villanuev
Constraint Violating Yak Guru

441 Posts

Posted - 05/22/2013 :  23:02:02  Show Profile  Reply with Quote
Guys,

Kindly please help me on how to get the derive result based on join statement. could not get the exact result.

please see below sample data and result: thanks.




CREATE TABLE #SAMPLE1
(itemid nvarchar(35),  inventtransid nvarchar(35), inventdimid nvarchar(35), JOURNALID nvarchar(35))
INSERT INTO #SAMPLE1
SELECT 'MOT2979','LT280264589','DIM4508728','PJ01716356' union all
SELECT 'MOT2979','LT280264590','DIM7043874','PJ01716356'



CREATE TABLE #SAMPLE2
(itemid nvarchar(35),  inventtransid nvarchar(35), toinventtransid nvarchar(35),  inventdimid nvarchar(35), toinventdimid nvarchar(35), JOURNALID nvarchar(35))
INSERT INTO #SAMPLE2
SELECT 'MOT2979','LT280264589','LT280264590','DIM4508728','DIM7043874','PJ01716356' 


CREATE TABLE #SAMPLE3
(inventdimid nvarchar(35), loation nvarchar(35))
INSERT INTO #SAMPLE3
SELECT 'DIM7043874','MARKET-L6' union all
SELECT 'DIM4508728','PR-L4-13'



RESULT:
itemid----FROMLOCATION--TOLOCATION
MOT2979--  MARKET-L6----PR-L4-13



visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/23/2013 :  00:41:58  Show Profile  Reply with Quote

SELECT s2.itemid,s31.loation AS FROMLOCATION,s3.loation  AS TOLOCATION
FROM #SAMPLE2 s2
INNER JOIN#SAMPLE3 s3
ON s3.inventdimid = s2.inventdimid 
INNER JOIN#SAMPLE3 s31
ON s31.inventdimid = s2.toinventdimid 


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Villanuev
Constraint Violating Yak Guru

441 Posts

Posted - 05/23/2013 :  01:54:39  Show Profile  Reply with Quote
Thanks Visakh for your prompt reply.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 05/23/2013 :  02:04:20  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.47 seconds. Powered By: Snitz Forums 2000