Wrox Programmer Forums
|
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
 
Old November 11th, 2005, 03:14 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old November 12th, 2005, 12:31 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

----------------------------------------------------------------------------------------------------
-- 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to convert query to stored procedure nanu yaru SQL Server 2000 2 April 1st, 2008 07:46 AM
Query Parameter of a Stored Procedure tarang SQL Server 2000 4 July 25th, 2007 11:43 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Oracle Stored Procedure and Microsoft Query Raoul Oracle 0 January 23rd, 2006 03:41 AM
Microsoft Query and Oracle stored procedure shl007 SQL Language 0 October 21st, 2003 02:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.