[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Excel MS Query - Issue with Cast

Posted on 2011-10-20
3
Medium Priority
?
893 Views
Last Modified: 2012-05-12
I'm trying to query some items and ran into an issue.  I have the following:

SELECT ID, CAST((COST/QTY) AS DECIMAL(6,2) AS TOTAL,
           X.DATE,
FROM   ITEM
            INNER JOIN
            (SELECT PART_ID, CAST((COST/QTY)) AS DECIMAL(6,2) AS TOTAL, DATE
             FROM ITEM_TRANS WHERE TYPE = 'I' AND CLASS='R')  X ON X.TOTAL = CAST((COST/QTY) AS DECIMAL(6,2))
             AND X.PART_ID = X.ID
WHERE  TYPE = 'O' AND CLASS = 'I'
AND ID = 'ABC888'

Incorrect column expression: 'CAST(COST/QTY) AS DECIMAL(6,2))'.

If I can't use cast, what can I use to convert my calculation so that it is 2 decimal places?  
0
Comment
Question by:holemania
3 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 37002358
use round(,2), as in
SELECT ID, round(COST/QTY,2) AS TOTAL,
           X.DATE
FROM   ITEM
            INNER JOIN
            (SELECT PART_ID, CAST((COST/QTY)) AS DECIMAL(6,2) AS TOTAL, DATE
             FROM ITEM_TRANS WHERE TYPE = 'I' AND CLASS='R')  X ON X.TOTAL = CAST((COST/QTY) AS DECIMAL(6,2))
             AND X.PART_ID = X.ID
WHERE  TYPE = 'O' AND CLASS = 'I'
AND ID = 'ABC888' 

Open in new window


Thomas
0
 
LVL 8

Accepted Solution

by:
VipulKadia earned 2000 total points
ID: 37005330
There were missing ')' at two points. I have corrected it. Try following :
SELECT ID, CAST((COST/QTY) AS DECIMAL(6,2)) AS TOTAL,
           X.DATE,
FROM   ITEM
            INNER JOIN
            (SELECT PART_ID, CAST((COST/QTY) AS DECIMAL(6,2)) AS TOTAL, DATE
             FROM ITEM_TRANS WHERE TYPE = 'I' AND CLASS='R')  X ON X.TOTAL = CAST((COST/QTY) AS DECIMAL(6,2))
             AND X.PART_ID = X.ID
WHERE  TYPE = 'O' AND CLASS = 'I'
AND ID = 'ABC888'

0
 

Author Closing Comment

by:holemania
ID: 37012894
Thanks didn't even catch that.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

834 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