Solved

Inner Join, SQL Function

Posted on 2014-10-09
5
430 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
  • 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 45

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 45

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 45

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now