use the convert function to run this query

Hi,

 I am a beginner, so be very simplistic with me, ok?

 I am trying to run this query:

update orders
set subtotal='59'
where id=47

And I get this:
disallowed implicit conversion from data type varchar to data type money. use the convert function to run this query.

 how do I do this? thanks!


mel150Asked:
Who is Participating?
 
bruintjeConnect With a Mentor Commented:
putting a value into ' and ' means sql server is seeing it as a varchar meaning text or string type, the data column subtotal is of a numeric type money so it will not allow you to put a string into a numeric field

if you want to do that you need to convert the value in a function like

update orders
set subtotal=CONVERT(money,'59')
where id=47
0
 
bruintjeCommented:
Hi mel150,

if the datatype of the column subtotal is numeric you don't need to use the quotes

try
update orders
set subtotal=59
where id=47

hope this helps a bit
bruintje
0
 
mel150Author Commented:
Thanks very much!! I didn't try the first one, but the second one worked!! Thanks so much!
0
 
bruintjeCommented:
glad i could help, but i should thank you for pushing me over to the SQL Server master level ;-)
0
 
mel150Author Commented:
Congratulations! Glad I could be of service. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.