views:

25

answers:

1

Hi All,

Pasted below is a stored procedure written in SQL Server 2005. My intent is to call this sproc from my ASP.NEt web application through the use of a wizard control. I am new to SQL Server and especially to stored procedures. I'm unsure why my parameters are not available to the web application and not visible in SSMS treeview as a parameter under my sproc name. Can you help me correct the sproc below so that the parameters are correctly instantiated and available for use in my web application?

Thanks, Sid

Stored Procedure syntax:

USE [Diel_inventory]
GO
/****** Object:  StoredProcedure [dbo].[AddQuote]    Script Date: 05/09/2010 00:31:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AddQuote] as
Declare @CustID int,
@CompanyName nvarchar(50),
@Address nvarchar(50),
@City nvarchar(50),
@State nvarchar(2),
@ZipCode nvarchar(5),
@Phone nvarchar(12),
@FAX nvarchar(12),
@Email nvarchar(50),
@ContactName nvarchar(50),
@QuoteID int,
@QuoteDate datetime,
@NeedbyDate datetime,
@QuoteAmt decimal,
@ID int,
@QuoteDetailPartID int,
@PartNumber float,
@Quantity int

begin

Insert into dbo.Customers
(CompanyName, Address, City, State, ZipCode, OfficePhone, OfficeFAX, Email, PrimaryContactName)
Values (@CompanyName, @Address, @City, @State, @ZipCode, @Phone, @FAX, @Email, @ContactName)

set @CustID = scope_identity()


Insert into dbo.Quotes 
(fkCustomerID,NeedbyDate,QuoteAmt)
Values(@CustID,@NeedbyDate,@QuoteAmt)

set @QuoteID = scope_identity() 


Insert into dbo.QuoteDetail
(ID) values(@ID)

set @ID=scope_identity()



Insert into dbo.QuoteDetailParts
(QuoteDetailPartID, QuoteDetailID, PartNumber, Quantity)
values (@ID, @QuoteDetailPartID, @PartNumber, @Quantity) 
END
+2  A: 

Your syntax is slightly incorrect (see the comments):

USE [Diel_inventory]
GO
/****** Object:  StoredProcedure [dbo].[AddQuote]    Script Date: 05/09/2010 00:31:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AddQuote] 
--// notice I just start defining parameters... no DECLARE, and no AS
@CustID int,
@CompanyName nvarchar(50),
@Address nvarchar(50),
@City nvarchar(50),
@State nvarchar(2),
@ZipCode nvarchar(5),
--//other parameters...
as
begin

 -- body of procedure
end
Jeff Meatball Yang
Thanks Jeff! Parms now visible. Now getting error:Cannot insert explicit value for identity column in table 'QUOTEDETAIL' when IDENTITY_INSERT is set to OFF. Where do I change Identity_Insert?
SidC
From what I can infer from your procedure, your QuoteDetail table has an ID column whose values should match the last-inserted @quoteID, yet it is an auto-incrementing IDENTITY column. That doesn't make sense to me - I would suggest having someone who is familiar with the application review how you're using the QuoteDetail table. Here's the link for how to do it -http://msdn.microsoft.com/en-us/library/aa259221(SQL.80).aspx - but it just doesn't seem like the right thing to do.
Jeff Meatball Yang