April 21, 2009 at 9:35 pm
ALTER PROCEDURE dbo.insertproblem
(
@onstationtime SMALLDATETIME,
@flttime Decimal,
@userid NVARCHAR (50),
@subject NVARCHAR (100)
)
AS
INSERT INTO TestingWork
(onstationtime,
flttime,
userID,
subject)
VALUES
(@onstationtime,
@flttime,
@subject
)
RETURN SCOPE_IDENTITY()
--DECLARE @reportID NVARCHAR (15)
DECLARE @autoID INT
DECLARE @RETURN_VALUE
SELECT @RETURN_VALUE AS autoID
UPDATE TestingWork SET reportID = 'PMR' + autoID
WHERE autoID = @autoID
April 21, 2009 at 10:10 pm
Do you have a question?
April 21, 2009 at 10:21 pm
can u provide table schema
🙂
April 21, 2009 at 10:26 pm
since you are just setting the ReportId to a string plus the autoid, you could make the column a calculated field and be done with it:
Alter Table TestingWork ADD NewReportId AS 'PMR' + convert(varchar(30),autoID)
but your proc is messed up; here's my best guess at a fix:
ALTER PROCEDURE dbo.insertproblem
(
@onstationtime SMALLDATETIME,
@flttime Decimal,
@userid NVARCHAR (50),
@subject NVARCHAR (100)
)
AS
Declare @InsertedID int
INSERT INTO TestingWork
(onstationtime,
flttime,
userID,
subject)
VALUES
(@onstationtime,
@flttime,
@subject
)
SELECT @InsertedID = SCOPE_IDENTITY()
/*this code did nothing, so i commented it out
--DECLARE @reportID NVARCHAR (15)
DECLARE @autoID INT
DECLARE @RETURN_VALUE
SELECT @RETURN_VALUE AS autoID
*/
UPDATE TestingWork SET reportID = 'PMR' + convert(varchar(30),@InsertedID)
WHERE autoID = @InsertedID
Lowell
April 22, 2009 at 5:46 am
Thank you so much. It worked perfectly.
Thanks a million.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply