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
How to Install JBOSS on windows xp
Help Please!
log4j called after unloading
Saving List in ASP.NET for use in second WCF Service
Two ISPs on the same network
how to remove "debugging" pop-up
AUTOCAD Bill of Materails Generation
Services Do Not Start Automatically
HTML table
Task Manager and regedit 'disabled by administrator', unable to access Safe Mode, Antivirus deactivated