Reputation: 2388
I need help with a SQL convert statement. I have NetQuanity (masterTable) which is a varchar(15) and I have another table with Purchase price (PO TABLE) which is money. When I try to multiply them in a SQL view is gives me the error:
Upvotes: 0
Views: 1078
Reputation: 1234
First of all you have a data definition problem. The first thing is to eliminate any non-numeric entries in the master table.
SELECT whatever FROM masterTable WHERE ISNUMERIC(NetQuanity)=1
The next step is to include this as a sub-query in the calculation.
In this query use CONVERT or CAST to convert the valid quanities to integer.
i.e.
CONVERT(INT, NetQuantity)
Upvotes: 0
Reputation: 143269
Maybe try using the CONVERT
function? CONVERT(money,NetQuantity)
.
Upvotes: 2
Reputation: 32278
If your field is a VARCHAR, you'll need to CAST to the appropriate data type prior to your operation. e.g.
CAST(myVarCharField as INT) * myIntField
Be forewarned however, if you attempt to CAST this field to a numeric data type and it's not numeric, you'll be in the same boat.
I would recommend using CAST
over CONVERT
in your example, for the following reason defined in this SO post:
Related: T-SQL Cast versus Convert
Upvotes: 4