Stored Procedures

  • 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,

    @userid,

    @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

  • Do you have a question?

  • can u provide table schema

    🙂

  • 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,

    @userid,

    @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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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