By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

Inserting decimal values into the table using insert statements

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. create table test1
  2. (
  3. number1  decimal(5,1),
  4. number2  decimal(5,1)
  5. )
  6.  
  7. DECLARE @count1 decimal(4,1)
  8. DECLARE @count2 decimal(4,1)
  9. DECLARE @count3 decimal(4,1)
  10. DECLARE @count4 decimal(4,1)
  11. DECLARE @count5 decimal(4,1)
  12. DECLARE @count6 decimal(4,1)
  13. set @count1 =6
  14. set @count2 =4
  15. set @count3 =10
  16. set @count4 =4
  17. set @count5 =0
  18. set @count6 =0
  19.  
  20. select @count4=(@count1/@count2) from test1
  21. select @count6=(@count1/@count2) from test1
  22. print @count4
  23. print @count6
  24.  
  25.  
  26. insert into test1 values('@count5','@count6')
Any help is appreciate.
Jul 17 '14 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,430
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.
Jul 17 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.