I am trying to do an insert into a table and then do a select to retrieve the id. I have a field in the table set up to be the identifier but I can not select from it. The insert works fine but the select does not process. Is there something I am doing wrong. Or some other factor with SQL SERVER that I need to be checking in order to do an insert and a select in the same procedure.
My stored procedure looks like this:
Alter Procedure stpCreateReturn
(
@copName varchar(70),
@copCity varchar(40),
@copProv char(2),
@copCountry varchar(30),
@copAddress varchar(70),
@copStatus varchar(70),
@copEstCost money
)
AS
INSERT INTO tblContProj (copName, copCity, copProv, copCountry, copAddress, copStatus, copEstCost)
VALUES (@copName, @copCity, @copProv, @copCountry, @copAddress, @copStatus, @copEstCost)
SELECT @@IDENTIFIER
return
So the insert works and puts the values into the table. copID is the name of the field that is the IDENTITY set to increment by 1 everytime a record is inserted but is not returned. The results of this query are this:
Running dbo."stpCreateReturn" ( @copName = test, @copCity = test, @copProv = te, @copCountry = test, @copAddress = test, @copStatus = test, @copEstCost = $1000 ).
Finished running dbo."stpCreateReturn".
the select should follow this but does not.
I am testing this in interdev.
Any help would be appreciated.
Bryant Moore
My stored procedure looks like this:
Alter Procedure stpCreateReturn
(
@copName varchar(70),
@copCity varchar(40),
@copProv char(2),
@copCountry varchar(30),
@copAddress varchar(70),
@copStatus varchar(70),
@copEstCost money
)
AS
INSERT INTO tblContProj (copName, copCity, copProv, copCountry, copAddress, copStatus, copEstCost)
VALUES (@copName, @copCity, @copProv, @copCountry, @copAddress, @copStatus, @copEstCost)
SELECT @@IDENTIFIER
return
So the insert works and puts the values into the table. copID is the name of the field that is the IDENTITY set to increment by 1 everytime a record is inserted but is not returned. The results of this query are this:
Running dbo."stpCreateReturn" ( @copName = test, @copCity = test, @copProv = te, @copCountry = test, @copAddress = test, @copStatus = test, @copEstCost = $1000 ).
Finished running dbo."stpCreateReturn".
the select should follow this but does not.
I am testing this in interdev.
Any help would be appreciated.
Bryant Moore