php-windows | 2003032
Date: 03/26/03
- Next message: skate: "Re: [PHP-WIN] uploading files"
- Previous message: Bobo Wieland: "[PHP-WIN] uploading files"
- In reply to: Herhuth, Ron: "[PHP-WIN] Simple Addition issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> $row['CA_state_source_income'] = "14,133";
> $row['IL_state_source_income'] = "10,556";
> When I check the value of $total_state_income it equals 24 not the expected 24,689.
> The datatype of the values returned from SQL Server are Varchar so I tried
> typecasting the values to integers before adding them to the running total.
>
> What am I doing wrong??
Try this and see what happend:
declare <email protected> varchar(8)
declare <email protected> varchar(8)
select <email protected> = "14,133"
select <email protected> = "10,556"
select convert(int, stuff( <email protected>, charindex(',', <email protected>, 1), 1, null)),
convert(int, stuff( <email protected>, charindex(',', <email protected>, 1), 1, null))
If you try this:
select convert(int, <email protected>), convert(int, <email protected>)
It will generate an error since the convert function gets confused
by the comma. If you have bigger numbers like: 1,234,567 then you
need to do the below with each string that might contain a comma:
select <email protected> = charindex(',', <email protected>, 1)
while ( <email protected> > 0)
begin
select <email protected> = stuff( <email protected>, <email protected>, 1, null)
select <email protected> = charindex(',', <email protected>, 1)
end
this will wash away all commas from a string.
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: skate: "Re: [PHP-WIN] uploading files"
- Previous message: Bobo Wieland: "[PHP-WIN] uploading files"
- In reply to: Herhuth, Ron: "[PHP-WIN] Simple Addition issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

