Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    26

    Unanswered: 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.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    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?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Jan 2005
    Posts
    26
    I found out something. I was not suppose to enter numeric values in quotations

  4. #4
    Join Date
    Jan 2005
    Posts
    26
    I just took the numerics out of quotations but now I get this error

    Code:
    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.

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  6. #6
    Join Date
    Jan 2005
    Posts
    26
    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.

  7. #7
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    so......
    update inventory set unitcost = .99 where item_id = 23456

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •