Must declare the scalar variables in storedprocedure in sql 2005

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 2
Reputation: miaaa00 is an unknown quantity at this point 
Solved Threads: 0
miaaa00 miaaa00 is offline Offline
Newbie Poster

Must declare the scalar variables in storedprocedure in sql 2005

 
0
  #1
Apr 3rd, 2007
I have created the following stored procedure in sql server 2005.I m using asp.net with C# 2005.
Can someone please rectify my errors why i m getting such type of the errors...


  1. ALTER PROCEDURE CompanyStoredProcedure
  2. @uspcompanyid INT NULL,
  3. @uspcompanyname VARCHAR(20),
  4. @uspaddress1 VARCHAR(30),
  5. @frmErrorMessage AS VARCHAR(256) OUTPUT,
  6. @RETURNVALUE AS INT OUTPUT,
  7. @RETURNID AS INT OUTPUT
  8. AS
  9. BEGIN
  10.  
  11. SET NOCOUNT ON
  12.  
  13. /*
  14.  
  15. RETURN_VALUE Comments
  16. 1 Data Inserted
  17. 2 Data Updated
  18. -9 Other errors
  19. */
  20. DECLARE @companyid INT,
  21. @companyname VARCHAR(20),
  22. @address1 VARCHAR(30)
  23.  
  24. --validation...
  25. IF ( @uspcompanyname IS NULL OR @uspcompanyname = '' )
  26. BEGIN
  27. SET @RETURNVALUE = -9
  28. SET @frmErrorMessage = 'Company Name is empty'
  29. RETURN -9
  30. END
  31.  
  32. IF EXISTS ( SELECT * FROM Companymaster WHERE Companyid = @companyid )
  33. BEGIN
  34. UPDATE Company
  35. SET companyname = @companyname,
  36. address1 = @address1
  37. WHERE companyid= @uspcompanyid
  38.  
  39. SET @frmErrorMessage = 'Company Name/Address has been updated'
  40. SET @RETURNVALUE = 2
  41. END
  42. ELSE
  43. BEGIN
  44. INSERT INTO companymaster ( companyname, address1 )
  45. VALUES (@companyname,@address1)
  46.  
  47. SET @frmErrorMessage = 'Company Name/Address info has been Inserted'
  48. SET @RETURNVALUE = 1
  49. END
  50.  
  51. SET NOCOUNT OFF
  52. END

THANXS in advance.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 2
Reputation: miaaa00 is an unknown quantity at this point 
Solved Threads: 0
miaaa00 miaaa00 is offline Offline
Newbie Poster

Re: Must declare the scalar variables in storedprocedure in sql 2005

 
0
  #2
Apr 3rd, 2007
I want SELECT @companyid = SCOPE_IDENTITY()
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Must declare the scalar variables in storedprocedure in sql 2005

 
0
  #3
Apr 4th, 2007
You don't need those declared variables, use the ones passed in as parameters (@upscompanyid, @upscompanyname and @upsaddress1). Delete the declared variables and make sure you are only using the parameters
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Must declare the scalar variables in storedprocedure in sql 2005

 
0
  #4
Apr 4th, 2007
Also you will need to declare another parameter as the OUTPUT version of companyid. This would then be set using the SCOPE_IDENTITY function after the insert
Last edited by davidcairns; Apr 4th, 2007 at 7:57 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC