I have created a stored procedure that does an update and insert to a small table. The SP is very simple. The table that is being used has a column called company_id
which is an identity column
. On inserts this value is returned to the calling code. The table is currently empty and I am testing the SP. Thus right now it should do an insert and return the ID to the calling code. I have run this SP in SQL mgmt studio and in debug from Visual Studio 2008 and it just will not do the Insert!!
It is driving me crazy. I am sure it is something very simple and/or obvious that I am missing. My SP code is listed below
ALTER PROCEDURE [dbo].[fm_Company_InsertUpdate]
@INCMP int = -1,
@TAXID VARCHAR(40) = null,
@CMP int OUTPUT
-- Update the row if it exists.
Update dbo.fm_Company SET company_name=@cname, company_legal_name=@legal, company_tax_id=@taxid
SET @CMP = @INCMP;
-- Insert the row if the UPDATE statement failed.
IF (@@ROWCOUNT = 0)
INSERT INTO dbo.fm_Company ([company_name],[company_legal_name],[company_tax_id])
VALUES (@CNAME, @LEGAL, @TAXID)
SET @CMP = SCOPE_IDENTITY();