?
Solved

Inner Join, SQL Function

Posted on 2014-10-09
5
Medium Priority
?
452 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 500 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 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1500 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 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1500 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 51

Accepted Solution

by:
Vitor Montalvão earned 1500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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
Suggested Courses

777 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