jd1991
asked on
Convert string from textbox into type money SQL Server 2005
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.
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
AS
BEGIN
from
SET NOCOUNT ON;
INSERT INTO Table1 (Amount)
VALUES(@Amount);
SELECT SCOPE_IDENTITY();
ASKER
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"
if i remove the ",1" bit it says "Disallowed implicit conversion from data type varchar to data type money"
sorry, remove the first comma. should be:
values (CONVERT(VARCHAR,@Amount,1 ))
values (CONVERT(VARCHAR,@Amount,1
ASKER
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
anyway i tired it with CONVERT(MONEY,@Amount,1) instead bit it doesn't work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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!
was a silly mistake - sometimes all it takes is someone to point the obvious and it makes it so much easier to find it!
insert into table1 (Amount)
values (CONVERT(VARCHAR,(@Amount,