Warning: MS SQL message: Disallowed implicit conversion from data type varchar to data type money, table 'test.dbo.test', column 'Yearly Income'. Use the CONVERT function to run this query. (severity 16) in c:\program files\apache group\apache\htdocs\3.php on line 14
In the php board the moderator already told me that CONVERT is a SQL Function that is used IN SQL. Well, question then, How do I use it correctly?
I want to be able to add a numeric value in an html form and have it added to the database in SQL. However I'd get the above message that i cannot go from varchar to money. So how would I go about using the CONVERT function, I've been looking around but all the examples I've seen are too confusing and use it in a different context. Please help.. Thanks.
In MS SQL, you do not enclose a money value in quotes, nor can you have anything other than your money indicator ($ for example) and your separators (with use of CAST).
As an example:
-- The following three INSERT statements work.
INSERT INTO TestMoney VALUES ($123.45)
INSERT INTO TestMoney VALUES ($123123.45)
INSERT INTO TestMoney VALUES (CAST('$444,123.45' AS MONEY) )
-- This INSERT statement gets an error because of the comma
-- separator in the money string.
INSERT INTO TestMoney VALUES ($555,123.45)