Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:41:53+00:00 2026-06-17T15:41:53+00:00

I have an Inventory table containing Master file info and 2 Movement History tables

  • 0

I have an Inventory table containing Master file info and 2 Movement History tables (Current Year and Last Year).

I want to use a Query to extract Movements from (say) June LAST Year to March THIS Year in Code, Date sequence.

I am relatively new to SQL and have tried to use the following INNER JOIN structure to do this:

SELECT Code, Descrip, Category, MLast.Date, MLast.DocNo, MCurr.Date, MCurr.DocNo
    FROM Stock AS S 
INNER JOIN MoveTrnArc MLast ON MLast.Stockcode = S.Code
    AND MLast.Date >='2011/06/01' AND MLast.Date <='2012/03/31'
INNER JOIN MoveTrn MCurr ON MCurr.Stockcode = S.Code 
    AND MCurr.Date >='2011/06/01' AND MCurr.Date <='2012/03/31'
ORDER BY S.Code

This creates a Query Table with the following column structure:

Code | Descrip | Category | Date | DocNo | Date | DocNo | 

…where the data from the LAST Year table appears in the first Date/DocNo columns and the CURRENT Year data appears in the second Date/DocNo columns.

What must I do to the Query to have each Movement in its own row or is there a better, more efficient Query to achieve this?

Also, I need the Movements listed in Code followed by Date sequence.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:41:54+00:00Added an answer on June 17, 2026 at 3:41 pm

    use union all instead of joins

    select s.Code , s.Descrip , s.Category , t.Date , t.DocNo  
    from 
    (
    select Stockcode, Date, DocNo from MoveTrnArc 
    union all
    select Stockcode, Date, DocNo from MoveTrn 
    ) t join Stock s on s.Code = t.Stockcode
    where t.Date >='2011/06/01' AND t.Date <='2012/03/31'
    

    beside careful with comparing dates, if Date column is type datetime and includes time you have to change t.Date <='2012/03/31' into t.Date <'2012/04/01' to include all the rows from 31st of march,
    as ‘2012/03/31’ is casted as ‘2012/03/31 00:00:00.000’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have two related tables(inventory and inventoryLocalization) on Sql Server 2005. the first table's
I have one table containing car inventory. This has two columns one is car_id
I have a table containing inventory ID | Product ID | In_Transit | Quantity
I have two temp tables, both populated by TSQL queries. Temp Table A containing
In this the catalog.xml file. I have two books who have the same inventory
We currently have a process where we receive an inventory file from a vendor
I have a table of inventory transactions. I need to select the dates of
I've got an inventory table that needs to have certain in each row, and
I have a table that logs inventory updates throughout the day. Table InventoryHistory: UpdateID
I have a INVENTORY table. There are many items inside. When I query it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.