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
SBS2008 , XP clients: Client side extensions failure.
OCS 2007 R2 Desktop Sharing
mouseleave event on panel, vb.net winforms
Need a solution for Sum within a Sum
RAID1 in MAX OSx
Forefront TMG Client Access
FTP Script via Unix
How to insert a single blob?
Outlook2007/ Exchange: Need password to connect
Can't send emails (Vista Business, United Kingdom, Demon Mailbox/Demon Broadband)