 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 11th, 2005, 03:14 AM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Stored Procedure Query
Hi,
I am facing one problem in stored procedure.I am using Professional sql server 2000 programming book.I am trying to execute one stored procedure , but it is giving error.
the procedure is - i am inserting one record into the orders table of northwind database.So OUTPUT keyword is there.When I click the check systax button on the window of stored procedure in enterprise manager,at that time it is generating an error message.the message is - Error 213 :Insert error:Column name or number of supplied values does not match table definition.
So what is that error.I am attaching the code.
USE Northwind
GO
CREATE PROC spInsertOrder
@CustomerID nvarchar(5),
@EmployeeID int,
@OrderDate smalldatetime=NULL,
@RequiredDate smalldatetime=NULL,
@ShippedDate smalldatetime=NULL,
@ShipVia int,
@Freight money,
@ShipName nvarchar(40)=NULL,
@ShipAddress nvarchar(60)=NULL,
@ShipCity nvarchar(15)=NULL,
@ShipRegion nvarchar(15)=NULL,
@ShipPostalCode nvarchar(10)=NULL,
@ShipCountry nvarchar(15)=NULL,
@OrderID int OUTPUT
AS
/* Create the new record */
INSERT INTO Orders
VALUES
(
@CustomerID,
@EmployeeID,
@OrderDate,
@RequiredDate,
@ShippedDate,
@ShipVia,
@Freight,
@ShipName,
@ShipAddress,
@ShipCity,
@ShipRegion,
@ShipPostalCode,
@ShipCountry
)
/* Move the identity value from the newly inserted record into
our output variable */
SELECT @OrderID = @@IDENTITY
So please send the solution
Anil
|
|

November 12th, 2005, 12:31 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
----------------------------------------------------------------------------------------------------
-- Create the table (if your not using northwind database)
----------------------------------------------------------------------------------------------------
-- drop table Orders
create table Orders ( Orderid int identity,
CustomerID nvarchar(5),
EmployeeID int null,
OrderDate smalldatetime NULL,
RequiredDate smalldatetime NULL,
ShippedDate smalldatetime NULL,
ShipVia int null,
Freight money null,
ShipName nvarchar(40) NULL,
ShipAddress nvarchar(60) NULL,
ShipCity nvarchar(15) NULL,
ShipRegion nvarchar(15) NULL,
ShipPostalCode nvarchar(10) NULL,
ShipCountry nvarchar(15) NULL,
)
GO
----------------------------------------------------------------------------------------------------
-- Create the proc
----------------------------------------------------------------------------------------------------
-- drop procedure spInsertOrder
CREATE PROC spInsertOrder
@CustomerID nvarchar(5),
@EmployeeID int,
@OrderDate smalldatetime=NULL,
@RequiredDate smalldatetime=NULL,
@ShippedDate smalldatetime=NULL,
@ShipVia int,
@Freight money,
@ShipName nvarchar(40)=NULL,
@ShipAddress nvarchar(60)=NULL,
@ShipCity nvarchar(15)=NULL,
@ShipRegion nvarchar(15)=NULL,
@ShipPostalCode nvarchar(10)=NULL,
@ShipCountry nvarchar(15)=NULL,
@OrderID int OUTPUT
AS
/* Create the new record */
INSERT INTO Orders
VALUES
(
@CustomerID,
@EmployeeID,
@OrderDate,
@RequiredDate,
@ShippedDate,
@ShipVia,
@Freight,
@ShipName,
@ShipAddress,
@ShipCity,
@ShipRegion,
@ShipPostalCode,
@ShipCountry
)
/* Move the identity value from the newly inserted record into
our output variable */
SELECT @OrderID = @@IDENTITY
return @OrderID
go
----------------------------------------------------------------------------------------------------
-- Insert a row and return the rowid (run this mutiple times, watch the count move)
----------------------------------------------------------------------------------------------------
declare @orderid int
exec spInsertOrder 'abc',123,'10/10/2005','10/10/2005','10/10/2005',1
,123.45,'shipname','addy','city','region','postal' ,'nowhere',@Orderid out
select @orderid
-----------------------------------------------------------------------------------------------------
select * from Orders
|
|
 |