Microsoft
Software
Hardware
Network
Question : Returning Output parameters from a stored proceedure
I have created a stored proceedure. Now I want to return some values from it. I want to return @resultCode and an inventory list something like this:
itemName Quantity date; itemName Quantity date; itemName Quantity date
I'm getting this error when trying to execute any of my outputs:
Server: Msg 8114, Level 16, State 1, Procedure uspupdatedb, Line 0
Error converting data type nvarchar to int.
Heres my execute:
DECLARE @resultCode int
EXEC Mydb.dbo.uspUpdatedb 2,'scented candle',.5,'7/31/2010',0
Exec @resultCode = uspUpdatedb OUTPUT
PRINT @resultCode
Here is my stored proceedure:
CREATE PROCEDURE uspUpdatedb
@storeID varchar(100),
@itemName varchar(50),
@Quantity varchar (8),
@date DateTime,
@resultCode int OUTPUT
AS
--SELECT to see if item exists.
IF EXISTS (SELECT * FROM InventoryList a JOIN StoreList b on a.StoreId=b.StoreId WHERE (a.StoreID=@StoreID) AND (a.ItemName=@ItemName)
AND (a.date=@date ))
--if item found in inventory list
SET @resultCode= 1
PRINT 'This date and quantity are already entered'
END
ELSE
BEGIN
UPDATE InventoryList
SET Quantity = Quantity + convert(float(8),@Quantity
WHERE itemName=@itemName AND StoreID=@StoreID
SET @resultCode=0
END
--SELECT to see if item doesn’t exist.
IF NOT EXISTS (SELECT * FROM InventoryList a JOIN StoreList b on a.StoreId=b.StoreId WHERE (a.StoreID=@StoreID) AND (a.ItemName=@ItemName)
AND (a.date=@date ))
--if item not found in inventory list
BEGIN
INSERT INTO InventoryList (StoreID,itemName,Quantity
,date) VALUES(@StoreID, @ItemName, convert(float(8),@Quantity
, @date)
SET @resultCode=0
END
--returns 0 on successful update or insert and 1 if error occured
RETURN @resultCode
GO
Thank-you for any help!
Answer : Returning Output parameters from a stored proceedure
DECLARE @resultCode int
SET @ResultCode = 0
EXEC Mydb.dbo.uspUpdatedb @storeID = 2, @itemName = 'scented candle',@Quantity = '.5', @Date = '7/31/2010', @resultCode = @resultCode OUTPUT
PRINT @resultCode
Random Solutions
Sending pdf files to client using webmethods
Cisco Unity Express to Trigger MWI on overlay DN
Reverse DNS does not match SMTP Banner
vmware player shows black screen on win 2003 server
Pass recordset from local sql server to remote sql server using access adp
Microsoft Office 2007 Clip art disappeared
Strip out ’s in mySQL query | XML Parsing Error: undefined entity
SSIS Promt user to enter date
Excel Help
Access - SQL user parameter entry