Page 1 of 1

syntax error inserting float numbers

Posted: Fri Sep 21, 2007 5:27 am
by fayna
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
I'm trying to execute the following sentence but I get an error:

Code: Select all

$result_id = odbc_prepare ($id_con,"insert into MEDICIONESTRABAJOS (ID, CODIGO, UDS,PVPU,EXPDTE) values ($id_trabajo,'$codigo',$uds,$pvpu, '$expdte')");
Warning: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line1: syntax error near '12.00'., SQL state 37000 in SQLExecute

The data types are:
ID: int
CODIGO: nvarchar
UDS and PVPU: float
EXPDTE: nvarchar

I obtain UDS and PVPU from a SELECT and the values can be 12.00 or 1225.50 (for example). But if I try doing this:

Code: Select all

$uds = 12.00;
$pvpu = 1225;
I don't get the error and the INSERT is done correctly, so I think the problem is creating the string.

What I'm doing wrong?, Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Sep 21, 2007 7:31 am
by xpgeek
Add quote around the values.

Posted: Fri Sep 21, 2007 8:31 am
by fayna
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I add quotes around the values:

[syntax="sql"]insert into MEDICIONESTRABAJOS (ID, CODIGO, UDS,PVPU,EXPDTE) values (658,'E001',12.00, 1225.50, '0157/03')
but I get the warning: quote not closed before string '12.00'


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Sep 21, 2007 8:51 am
by xpgeek
Quote ALL values.