Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS SQL Insert query

Status
Not open for further replies.

larrylapointe

IS-IT--Management
Jan 9, 2002
3
AU

I am writing a PHP script to automatically import data from a text file into an MS SQL database. Unfortunately when I try to run execute the SQL Insert statment the server seems to be converting a numeric value into a varchar field...

Here are the lines in php:

$Query = "Insert into Table (PartyId,Code,Date,Type) VALUES (101,'A1','9-Mar-2003 00:00:00','CASH')";

$Result = mssql_query($Query);

(Note PartyId is a numeric field, while all others are varchar.)

Here is the message that is returned:

Warning: mssql_query() [function.mssql-query]: message: Error converting data type varchar to numeric. (severity 16) in C:file.php

It appears that the number 101 is being converted to a varchar ???

BTW: I am running php 4.3.1 on an Apache2 server under Win2000. The SQL Server is MSSQL Server 2000.

Ideas???
 
I do not think the error is because of the value 101.

The error message states that the error is because of trying to convert a varchar to a numeric. If the problem were in the value 101, then it would have reported an error converting numeric to varchar, which doesn't happen anywhere near as often.

I'd take a look at your other values. Want the best answers? Ask the best questions: TANSTAAFL!
 
Hmmm....

I have double checked the database Table that Code, Date, and Type are varchars and that PartyId is, in fact, a numeric.

I have also experimented using the process of elimination to identify that this field is where the problem is.

Is it possible that somehow the 101 is being cast to a string/char type when it is passed to the server?

Very frustrating...

 


And a new day dawns...

Not sure why, but when I added the intervening fields between PartyId and Code, the insert is working. Incidently, the second field (after PartyId) *was* a numeric....I'm not really sure why I needed to include these extra fields in the statement, but it works...

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top