Tuesday, February 14, 2012

CONVERT function

I get this error when I run this query, How do I use the CONVERT function in this scenario

insert into Inventory (Item_ID,
Inventory_ID,Perishable_indicator, Perishable_Date,
Department_ID, Category, Description, Unit_of_Measure,
Quantity_on_Hand, Unit_Cost, Master_Pack_Quantity,
Supplier_ID)
values
('23456','8263458', 'Yes', 'Feb 25 2005
12:00AM','695', 'Produce', 'Apple', 'per lb', '6000',
'0.99', '10000', '893')

Server: Msg 260, Level 16, State 1, Line 1
Disallowed implicit conversion from data type varchar
to data type money, table 'Final
Project.dbo.Inventory', column 'Unit_Cost'. Use the
CONVERT function to run this query.Have you tried looking up CAST and CONVERT in Books Online?

And why are you submitting your numeric values as strings in the first place?|||I found out something. I was not suppose to enter numeric values in quotations|||I just took the numerics out of quotations but now I get this error

insert into Inventory (Item_ID, Inventory_ID, Perishable_indicator, Perishable_Date, Department_ID, Category, Description, Unit_of_Measure, Quantity_on_Hand, Unit_Cost, Master_Pack_Quantity, Supplier_ID)
values
('23456','8263458', 'Yes', 'Feb 25 2005 12:00AM','695', 'Produce', 'Apple', 'per lb', '6000', 0.99, '10000', '893')

Server: Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_Inventory'. Cannot insert duplicate key in object 'Inventory'.
The statement has been terminated.|||Pretty high probability is that you've already got a row with an Item_id value of 23456. If there is a primary key defined, there can only be one row with a given value for the PK.

-PatP|||oh ok, that makes sense. i entered in this info via table previously but now i'm just trying to put that info into code.|||so.....
update inventory set unitcost = .99 where item_id = 23456
:eek:

No comments:

Post a Comment