Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help!Error converting data type varchar to numeric

Author  Topic 

Jeaneene
Starting Member

2 Posts

Posted - 2008-08-01 : 23:51:10
So, I'm getting that message, and I'm not sure what to do.

Here is my code for creating my "Employee" table:

CREATE TABLE Employee
(
Employee_ID BigInt PRIMARY KEY IDENTITY(100,25),
Last_name Varchar(50) NOT NULL,
First_name Varchar(50) NOT NULL,
Address Varchar(100) NOT NULL,
City Varchar(50) NOT NULL,
State Varchar(2) NOT NULL,
Telephone_area_code Varchar(3) NOT NULL,
Telephone_number Varchar(8) NOT NULL,
EEO_1_classification VarChar(50) NOT NULL,
Hire_date Varchar(10) NOT NULL,
Salary Decimal(7,2) NOT NULL,
Gender Varchar(1) NOT NULL,
Age Varchar(2) NOT NULL
);
GO

Now, here is my code to insert 1 row of data:
INSERT INTO Employee
(Last_name,First_name,Address,City,State,Telephone_area_code,Telephone_number,EEO_1_classification,Hire_date,Salary,Gender,Age)

VALUES
('Edelman','Glenn','175 Bishops Lane','La Jolla','CA','619','555-0199','Sales Workers','10-07-2003','$21,500.00','M','64')


What have I done wrong? Please help! Thanks in advance!

raky
Aged Yak Warrior

767 Posts

Posted - 2008-08-02 : 00:21:04
quote:
Originally posted by Jeaneene

So, I'm getting that message, and I'm not sure what to do.

Here is my code for creating my "Employee" table:

CREATE TABLE Employee
(
Employee_ID BigInt PRIMARY KEY IDENTITY(100,25),
Last_name Varchar(50) NOT NULL,
First_name Varchar(50) NOT NULL,
Address Varchar(100) NOT NULL,
City Varchar(50) NOT NULL,
State Varchar(2) NOT NULL,
Telephone_area_code Varchar(3) NOT NULL,
Telephone_number Varchar(8) NOT NULL,
EEO_1_classification VarChar(50) NOT NULL,
Hire_date Varchar(10) NOT NULL,
Salary Decimal(7,2) NOT NULL,
Gender Varchar(1) NOT NULL,
Age Varchar(2) NOT NULL
);
GO

Now, here is my code to insert 1 row of data:
INSERT INTO Employee
(Last_name,First_name,Address,City,State,Telephone_area_code,Telephone_number,EEO_1_classification,Hire_date,Salary,Gender,Age)

VALUES
('Edelman','Glenn','175 Bishops Lane','La Jolla','CA','619','555-0199','Sales Workers','10-07-2003','$21,500.00','M','64')


What have I done wrong? Please help! Thanks in advance!



You had assigned decimal datatype to salary column and you are trying to store special character '$' hence it is giving error. why you have assigned AGE column with Varchar instead of int?
Go to Top of Page

Jeaneene
Starting Member

2 Posts

Posted - 2008-08-02 : 00:29:38
Thank you! I didn't even think that the "$" would cause a problem. Also, thanks for the tip about the "Age" column!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-04 : 04:09:31
Also dont use comma when expressing value to decimal column
Formation matters only if you want to show them somewhere

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pkuchaliya
Starting Member

49 Posts

Posted - 2008-08-04 : 04:12:04
Dont use varchar for age, and dont insert special character in salary column.

pankaj
Go to Top of Page

padamgondenk2001
Starting Member

4 Posts

Posted - 2008-08-05 : 05:15:35
Insert value in Salery Field Numric Value and Age dataty specify as numric datatype.

Padamgonde N. K
Software Developer,
HOL Infosolution Pvt. Ltd.
Pune, India
Go to Top of Page
   

- Advertisement -