Skip to Content

Available Inventory Report

I am trying to write a query where I can find out what items are in stock, after deducting the committed quantities.

This works:

SELECT TOP 10 T1.[ItemCode], ( T1.[OnHand] - T1.[IsCommited] ) as [AVAILABLE] FROM [OITM] T1 ORDER BY [AVAILABLE]

But if I try to add [AVAILABLE] to the where clause:

SELECT TOP 10 T1.[ItemCode], ( T1.[OnHand] - T1.[IsCommited] ) as [AVAILABLE] FROM [OITM] T1 WHERE [AVAILABLE] > '0'

it gives the error "Invalid Column Name." I have tried this several different ways, all without success.

Any help would be appreciated.

Thanks,

Seth

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Feb 21, 2019 at 03:52 PM

    You cannot use alias in the WHERE clause directly. Try this:

    SELECT TOP 10 
      T1.[ItemCode], 
      ( T1.[OnHand] - T1.[IsCommited] ) as [AVAILABLE] 
    FROM 
      [OITM] T1 
    WHERE 
      ( T1.[OnHand] - T1.[IsCommited] )  > 0
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 22, 2019 at 01:20 PM

    Perfect! Yeah, I should have thought of that.

    Thanks,

    Seth

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.