Inserting decimal values into the table using insert statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monapatel
    New Member
    • Jul 2014
    • 1

    Inserting decimal values into the table using insert statements

    Hello all,

    i am trying to insert decimal data (i.e 3.2,4.5,6.8 )into table but receiving error: "Error converting data type varchar to numeric."

    Here is the my code that i use to inserting values.

    Code:
    create table test1
    (
    number1  decimal(5,1),
    number2  decimal(5,1)
    )
    
    DECLARE @count1 decimal(4,1)
    DECLARE @count2 decimal(4,1)
    DECLARE @count3 decimal(4,1)
    DECLARE @count4 decimal(4,1)
    DECLARE @count5 decimal(4,1)
    DECLARE @count6 decimal(4,1)
    set @count1 =6
    set @count2 =4
    set @count3 =10
    set @count4 =4
    set @count5 =0
    set @count6 =0
    
    select @count4=(@count1/@count2) from test1
    select @count6=(@count1/@count2) from test1
    print @count4
    print @count6
    
    
    insert into test1 values('@count5','@count6')
    Any help is appreciate.
    Last edited by Rabbit; Jul 17 '14, 07:46 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Remove the quotes around your variable names. It's trying to insert the string '@count5' and not the value stored in @count5.

    Comment

    Working...