Showing posts with label oney. Show all posts
Showing posts with label oney. Show all posts

Friday, February 24, 2012

Convert money columns to update?

Hi Guys

I need your help again, I am try to update several columns and the data type is 'money'.

Below is the code I have used:

UPDATE CAT_Products
SET

UnitCost ='10.00',
UnitCost2 = '10.00',
UnitCost3 = '10.00',
UnitCost4 = '10.00',
UnitCost5 = '10.00',
UnitCost6 = '10.00'

WHERE ProductCode = '0008'

But it will not update, instead I get this error:

-----------------------------------------------------------

>[Error] Script lines: 1-9 --------
Disallowed implicit conversion from data type varchar to data type money, table 'dbo.CAT_Products', column 'UnitCost'. Use the CONVERT function to run this query.

More exceptions ... Disallowed implicit conversion from data type varchar to data type money, table '.dbo.CAT_Products', column 'UnitCost2'. Use the CONVERT function to run this query.

-----------------------------------------------------------

The error message indicates that I need to use the convert function. But the columns data type is set at 'money' not 'varcher' . So do I need to convert data type to 'varcher' in order to update and convert back to data type 'money' when update complete? Or do I need to indicate in the update statement that data type is already 'money'? I am not sure how I would either.

Thanks

try:

UPDATE CAT_Products
SET

UnitCost =convert(money,'10.00'),
UnitCost2 = convert(money,'10.00'),
UnitCost3 = convert(money,'10.00'),
UnitCost4 =convert(money,'10.00'),
UnitCost5 = convert(money,'10.00'),
UnitCost6 = convert(money,'10.00')

WHERE ProductCode = '0008'

|||

Hi jpazgier

Thank you for your reply and code.

I am pleased to say that your code worked first time.

A great help.

Cheers.

Friday, February 10, 2012

convert data to currency

I have a column - datatype 'money' and my price variable is (for instance)
8450
how do I put this value into the money column without getting this error?

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC SQL Server Driver][SQL Server]Disallowed implicit conversion from data type varchar to data type money, table 'db196009544.dbo196009544.vehicles', column 'price'. Use the CONVERT function to run this query.

ASP VBScript
I am using this syntax:

price = Upload.Form("price") '--this gives 8450--

SQL="UPDATE vehicles SET price='" & price & "' WHERE id=" & request.queryString("linkID") & ""

Thanks
markDo you define the variable as a daatype...sounds like it's defined as char if you are|||not sure!
I have tried using cCur() and various others when estting the variables but to no avail.

I suspect it has to be done in the SQL string, but can't make that work either.|||I mean it lloks like vb, and I'd ratyher keep my hands clean, buit can you do?

price = Upload.Form(price)

Also, you'd be way better off using stored procedures|||removing the single quotes from the price variable apears to have solved that but now the datetime variable is playing up in the same fashion, so I can't be sure if all is well with the price.
see my next post!