Solved

Inner Join, SQL Function

Posted on 2014-10-09
5
443 Views
Last Modified: 2014-10-12
Could someone explain me these line of code especially with the inner join and the select statement. Is this   f31122.wtan8 a reference to another table?  It will be greatly appreciated. Thank you.


 Declare @WORouting Table
(   WONbr float, 
    OpCode float, 
    OpCodeDesc nvarchar(100), 
    EstHours float, 
    ActHours float, 
    EmpNbr float, 
    EmpName nvarchar(100),
    WAITM float
 )


  Insert @WORouting
         (WONbr, 
          OpCode ,
          OpCodeDesc ,
          EstHours ,
          ActHours,
          EmpNbr ,
          EmpName ,
          WAITM 
 )
  Select wo.WONbr, 
         f3003.IROPSQ / 100, 
         f3003.IRDSC1, 
         f3003.IRRUNL, 
         sum(f31122.wthrw / 100), 
         f31122.wtan8,
         '',
         f3003.IRKIT
 
    from @WorkOrders wo
         inner join ps_prod.proddta.f3003 f3003 (nolock)
                 on wo.waitm = f3003.irkit  
                and ltrim(rtrim(f3003.IRMMCU)) = '308'
         inner join ps_prod.proddta.f31122 f31122 (nolock) 
                 on f3003.irkit = f31122.wtkit
                and f3003.iropsq = f31122.wtopsq
 group by wo.WONbr, 
         f3003.IROPSQ / 100, 
         f3003.IRDSC1, 
         f3003.IRRUNL, 
         f31122.wtan8,
         f3003.IRKIT

Open in new window

0
Comment
Question by:yguyon28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 125 total points
ID: 40370526
f31122 is a reference to the table ps_prod.proddta.f31122 (see line 36).

Within that table, there is a field called wtan8
0
 
LVL 49

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 375 total points
ID: 40370531
f31122  is a table from ps_prod database and proddta schema (ps_prod.proddta.f31122).
What your script is doing is insert data in a table variable (@WORouting ) with information collected between another table variable (@WorkOrders)  and 2 tables (f3003 and f31122) where IRMMCU it's '308'.
0
 
LVL 49

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 375 total points
ID: 40370560
From your other question:
----------------------------------------------------------------
-- Step 2: Fetch estimate/actual details for the work orders in question
--        F4801: work order header
--        F3003: routing master has operations and op desc
--                 (f4801.waitm = f3003.irkit
--                  f3003.IRDSC, f3003.IROPSQ / 100, f3003.RUNL est hours
--        F3112: summary work order routing -- not terribly useful because they want hours by person
--        F31122: individual hours by employee
--                f31122.wtkit = f3003.irkit, f31122.wtopsq = f3003.iropsq)
--                f31122.wthrw is actual hours
--                f31122.wtan8 = employee nbr (look up name in f0101)
--          
----------------------------------------------------------------
0
 

Author Comment

by:yguyon28
ID: 40370721
I guess I'm having a hard time understanding this inner join

 from @WorkOrders wo
         inner join ps_prod.proddta.f3003 f3003 (nolock)
                 on wo.waitm = f3003.irkit  
                and ltrim(rtrim(f3003.IRMMCU)) = '308'
         inner join ps_prod.proddta.f31122 f31122 (nolock)
                 on f3003.irkit = f31122.wtkit
                and f3003.iropsq = f31122.wtopsq
0
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 375 total points
ID: 40370743
What you don't understand in that INNER JOIN?
The INNER JOIN clause represents the relationship between tables. So for you assure the integrity of data between tables you need to give that information to the engine and it's what for the INNER JOIN is necessary.
NOLOCK means that the engine to not wait if the table is locked by other process so it allows dirty reads (data that can't be confirmed if it's changed during the SELECT).
LTRIM(RTRIM((f3003.IRMMCU)) is LeftTrim and RightTrim the values on the specified field so will return a value without leading and ending spaces. In that case the purpose is to accept '   308' or '308   ' as '308'.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question