Solved

Inner Join, SQL Function

Posted on 2014-10-09
5
439 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 47

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 47

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 47

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
best counters for cpu high usage 3 35
SQL Server Designer 19 47
What's wrong with this T-SQL Foreign Key? 7 46
SQL Syntax: How to force case sensitive query? 2 32
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.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

825 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