Home All Groups Group Topic Archive Search About

Convert when multiplying smallints

Author
12 Aug 2005 12:42 PM
hals_left
Hi I have two columns of type small int that cause overflow when
multiplied.

SELECT Convert(Bigint,Quantity*UnitCost) FROM Transactions
SELECT Convert(varchar(12),Quantity*UnitCost) FROM Transactions

Arithmetic overflow error converting expression to data type smallint.

What is the correct way to select this?

Thanks

Author
12 Aug 2005 12:49 PM
Alejandro Mesa
Try,

SELECT cast(Quantity as bigint) * UnitCost FROM Transactions


AMB


Show quote
"hals_left" wrote:

> Hi I have two columns of type small int that cause overflow when
> multiplied.
>
> SELECT Convert(Bigint,Quantity*UnitCost) FROM Transactions
> SELECT Convert(varchar(12),Quantity*UnitCost) FROM Transactions
>
> Arithmetic overflow error converting expression to data type smallint.
>
> What is the correct way to select this?
>
> Thanks
>
>
Author
12 Aug 2005 12:49 PM
Narayana Vyas Kondreddi
Which of those statements produce the error? And do you know what values are
producing the error? Small int can go upto 32,767
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/


"hals_left" <cc900***@ntu.ac.uk> wrote in message
news:1123850544.468656.282800@g14g2000cwa.googlegroups.com...
Hi I have two columns of type small int that cause overflow when
multiplied.

SELECT Convert(Bigint,Quantity*UnitCost) FROM Transactions
SELECT Convert(varchar(12),Quantity*UnitCost) FROM Transactions

Arithmetic overflow error converting expression to data type smallint.

What is the correct way to select this?

Thanks
Author
12 Aug 2005 12:51 PM
Lee-Z
SELECT Cast(Quantity as Bigint)*Cast(UnitCost as Bigint) FROM Transactions

works....but best option?

Lee-Z

Show quote
"hals_left" <cc900***@ntu.ac.uk> wrote in message
news:1123850544.468656.282800@g14g2000cwa.googlegroups.com...
> Hi I have two columns of type small int that cause overflow when
> multiplied.
>
> SELECT Convert(Bigint,Quantity*UnitCost) FROM Transactions
> SELECT Convert(varchar(12),Quantity*UnitCost) FROM Transactions
>
> Arithmetic overflow error converting expression to data type smallint.
>
> What is the correct way to select this?
>
> Thanks
>
Author
12 Aug 2005 1:20 PM
hals_left
>SELECT Cast(Quantity as Bigint)*Cast(UnitCost as Bigint) FROM Transactions

Thanks, that does it.

AddThis Social Bookmark Button