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
Sharing camcorder footage
How do I delete the default recipient policy in exchange 2010?
SBS2008 Folder redirections feature stability ?
The fool says in his heart ...
PDFs and iPads
Is there any way to limit what the users see in shared calendars in Exchange 2003 / Exchange 2007?
Using VLookup for Data Validation
WebService Client problem
web design vs dev
How to write script for the requirment?