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!

Tough One, Stored Procedure Not Functoining

Status
Not open for further replies.

dpwsmw

MIS
Apr 2, 2003
76
US
Below is a stored Procedure I have wrote, However it fails with the following error
**************************************************
Server: Msg 213, Level 16, State 4, Procedure p_insertCustomer, Line 23
Insert Error: Column name or number of supplied values does not match table definition.
**************************************************

I have checked the syntax and I have checked and ensured all things exist in the table, I am at a loss. Please help.
**************************************************

IF exists(
SELECT * from SysObjects where name = 'p_insertCustomer' and type='P'
)
BEGIN
drop proc p_insertCustomer
END
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE p_insertCustomer
@Division varchar(2) = null,
@CustomerNumber varchar(7)= null,
@CustomerName varchar(30)= null,
@AddressLine1 varchar(30)= null,
@AddressLine2 varchar(30)= null,
@AddressLine3 varchar(30)= null,
@City varchar(20)= null,
@State varchar(2)= null,
@ZipCode varchar(10)= null,
@CountryCode varchar(3)= null,
@SalesPersonCode varchar(4)=null,
@EmailAddress varchar(50)= null,
@URLAddress varchar(50)= null,
@CreditLimit dec(19,7)= null,
@AccountId uniqueidentifier,
@FaxNumber varchar(17)= null,
@PhoneNumber varchar(17) = null,
@ContactCode varchar(10)= null,
@TermsCode varchar(2)= null
AS
BEGIN
INSERT INTO [MAS_001].[dbo].[AR1_CustomerMaster]
SELECT
@Division,
@CustomerNumber,
@CustomerName,
@AddressLine1,
@AddressLine2,
@AddressLine3,
@City,
@State,
@ZipCode,
@CountryCode,
@SalesPersonCode,
@EmailAddress,
@URLAddress,
@CreditLimit,
@AccountId,
@FaxNumber,
@PhoneNumber,
@ContactCode,
@TermsCode

END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
 
Read this:
Code:
Insert Error: Column name or number of supplied values does not match [b]table definition[/b].
This means table has 42 columns and you specified <> 42 in INSERT.

Try always to use INSERT INTO <table> (list_of_columns_here). This can be a pain in the a** for typing (OK, QA may help a lot) but prevents this and some other errors, in particular when table structure gets changed.

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.
 
Make sure you aren't inserting a record into a field that is an identity column.

i.e. if the last column in the table is an identity column and the total columns in the table = 42, then you would insert only the first 41 records.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top