Convert string from textbox into type money SQL Server 2005

Posted on 2010-09-05
Last Modified: 2012-08-13
I usually use SQL Server 2008 and the following code works perfectly with it so I think its an SQL Server 2005 thing but am not 100% sure.

I am getting an amount of money from a textbox and inputting it into a database table with a field 'money'

am using a stored procedure - it works fine with every other field apart from the money field.

the code below doesn't work (i'm passing through a textbox (string))

I tried using CONVERT(MONEY, @Amount) instead of just @Amount but it made no difference.

anyone know what i'm missing?

p.s. - before someone asks I have checked that it is passing the correct textbox etc.
ALTER PROCEDURE [dbo].[procedurename]
	@Amount money = null

	INSERT INTO Table1 (Amount)

Open in new window

Question by:jd1991
  • 4
  • 2
LVL 28

Expert Comment

ID: 33607276
try this

insert into table1 (Amount)
values (CONVERT(VARCHAR,(@Amount,1)))


Author Comment

ID: 33607304
nope doesn't work, says 'incorrect syntax near ',' (thats the commar with the 1 after it)

if i remove the ",1" bit it says "Disallowed implicit conversion from data type varchar to data type money"
LVL 28

Expert Comment

ID: 33607318
sorry, remove the first comma. should be:

values (CONVERT(VARCHAR,@Amount,1))

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.


Author Comment

ID: 33607342
that brings up an error saying cannot convert from data type varchar to data type money - which makes sense as what you have told me to do is convert a string to varchar and put varchar into a field which is of data type money... which doesn't really make sense.

anyway i tired it with CONVERT(MONEY,@Amount,1) instead bit it doesn't work

Accepted Solution

Valliappan AN earned 500 total points
ID: 33607421
Can you check if this works:

      INSERT INTO Table1 (Amount)

If it does,then I dont think its SQL 2005 issue, but data issue.


Author Comment

ID: 33607451
thanks looks like it is a data issue, strange thing is though that it does work perfectly with sql server 2008. I'll have a look and see exactly what it is passing to it.

Author Comment

ID: 33607463
thank you - got it working :)
was a silly mistake - sometimes all it takes is someone to point the obvious and it makes it so much easier to find it!

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Slow Connectivity over ODBC 8 32
SQL Server tables join on parse list 6 21
SSRS 2013 - Overlapping reports 2 19
sql server service accounts 4 19
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now