SQL Insert statement error

Msg 8152, Level 16, State 14, Line 2

Page 1 of 1

3 Replies - 3061 Views - Last Post: 15 January 2008 - 01:58 PM Rate Topic: -----

#1 PonyDriver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 27-April 07

SQL Insert statement error

Post icon  Posted 14 January 2008 - 10:02 PM

Hi,
I was hoping to get a little help with a problem I am having with an insert statement that keeps returning this error message:


"Msg 8152, Level 16, State 14, Line 2 String or binary data would be truncated. The statement has been terminated."



I have created this table:
CREATE TABLE Job_title
(
	Job_title_id int IDENTITY NOT NULL,
	EEO_1_Classification varchar(35) NOT NULL,
	Job_title varchar(50) NOT NULL,
	Job_description varchar NOT NULL,
	Exempt_non_exempt_status varchar(15) NOT NULL,
)



And I am trying to execute this Insert statement when I get the error message I noted above:

INSERT INTO Job_title
	(EEO_1_Classification, Job_title, Job_description, Exempt_non_exempt_status)
VALUES
	('Sales Workers', 'Cashier', 'Operates cash register to itemize and total customer’s purchases in grocery
store', 'Non-Exempt')



I have a feeling I am missing something simple, but I'm not sure and any help would be greatly appreciated.

Thank you in advance for any help offered.

Tim

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Insert statement error

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: SQL Insert statement error

Posted 15 January 2008 - 12:23 AM

That error is saying you're trying to put a string that is larger than the size set for a column, so its one of these values

EEO_1_Classification varchar(35) NOT NULL,
Job_title varchar(50) NOT NULL,
Exempt_non_exempt_status varchar(15) NOT NULL


Because those 3 are the only columns with a set size.
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: SQL Insert statement error

Posted 15 January 2008 - 01:34 AM

I believe the problem is this column.
Job_description varchar NOT NULL,

You did not specify a size for the varchar and I believe the default is 50.
Here is the data you are trying to insert into that column, much more than 50 characters.
'Operates cash register to itemize and total customer’s purchases in grocery
store'

Try specifying a size for the varchar.
Job_description varchar(255) NOT NULL,

Was This Post Helpful? 0
  • +
  • -

#4 PonyDriver  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 27-April 07

Re: SQL Insert statement error

Posted 15 January 2008 - 01:58 PM

Thank you both for responding and for offering your help. I actually figured it out last night about 30 minutes after I posted my request for help. Darndest thing though, I used that same code in last weeks assignment and it worked with no problem and that's why I couldn't understand why it wouldn't work this week, once I got over my stubbornness and tried defining the "varchar" size for "Job_description" it worked beautifully.

Great lesson in this for me though, don't be so stubborn, staring at the error message thinking to yourself: "but it worked last week" will not fix the problem! :-)

Thanks again for your help.

Tim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1