Board index » delphi » I have a problem with converting between Numeric type and String Type

I have a problem with converting between Numeric type and String Type

I used to use sql string without using param, such as
" where POWN_ID='''+TypeId+''''.
When I connect to Interbase, It works Ok.
Even,  POWN_ID is Numeric type and TypeID is String.

Now, The converting error is occured when I connect to MSSQL server.

Do you have any idea to solve the problem with minizing to modify source
code?

 

Re:I have a problem with converting between Numeric type and String Type


Hi Jonn

Maybe the decimal separator ? Try a point like 10.2 not a comma like 10,2.

so long

Joon Chung schrieb:

Quote
> I used to use sql string without using param, such as
> " where POWN_ID='''+TypeId+''''.
> When I connect to Interbase, It works Ok.
> Even,  POWN_ID is Numeric type and TypeID is String.

> Now, The converting error is occured when I connect to MSSQL server.

> Do you have any idea to solve the problem with minizing to modify source
> code?

Re:I have a problem with converting between Numeric type and String Type


var
    TypeID, SQLText: String;

begin
    TypeID := '10.2';
    SQLText := 'SELECT * FROM SomeTable ';
    SQLText := SQLText + 'WHERE POWN_ID = ' + TypeID';
end;

Quote
Joon Chung wrote:
> I used to use sql string without using param, such as
> " where POWN_ID='''+TypeId+''''.
> When I connect to Interbase, It works Ok.
> Even,  POWN_ID is Numeric type and TypeID is String.

> Now, The converting error is occured when I connect to MSSQL server.

> Do you have any idea to solve the problem with minizing to modify source
> code?

Re:I have a problem with converting between Numeric type and String Type


Hi Joon!

On Mon, 17 May 1999 11:52:10 -0700, "Joon Chung" <JCh...@etnbids.com>
wrote:

Quote
>Now, The converting error is occured when I connect to MSSQL server.

You can not compare numeric field with string constant, for instance
following SQL line would cause an error if the field POWN_ID is
numeric ....

where POWN_ID= '12.34'

tomi.

Re:I have a problem with converting between Numeric type and String Type


On Mon, 17 May 1999 11:52:10 -0700, "Joon Chung" <JCh...@etnbids.com>
wrote:

Quote
>I used to use sql string without using param, such as
>" where POWN_ID='''+TypeId+''''.
>When I connect to Interbase, It works Ok.
>Even,  POWN_ID is Numeric type and TypeID is String.

>Now, The converting error is occured when I connect to MSSQL server.

>Do you have any idea to solve the problem with minizing to modify source
>code?

Use the CAST function to convert (for the comparison only) one value to a
data type that matches the other comparison value. For example:

  SELECT *
  FROM YourTable Y
  WHERE POWM_ID = CAST(TypeID AS NUMERIC)

Or...

  SELECT *
  FROM YourTable Y
  WHERE CAST(POWM_ID AS CHAR(4)) = TypeID

//////////////////////////////////////////////////////////////////////////
Steve Koterski                    "My problem lies in reconciling my gross
Technical Publications            habits with my net income."
INPRISE Corporation                             -- Errol Flynn (1909-1959)
http://www.borland.com/delphi

Other Threads