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 save images and image file paths into SQL from delphi form
Comparison Netgear ReadyNAS vs. Buffalo Terastation
WAKE ON LAN
OWA setup issues in Exchange 2010
Trying to upload files to my site
OneNote 2010 default search using last scope
Enteprise Application Documentation Application
Sybase Database truncate table issues
Perl error: invalid command name "use"
SQL 2k Database restore using only MDF flies