Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:47:18+00:00 2026-06-09T18:47:18+00:00

I have modified a stored procedure and added an extra parameter to be added

  • 0

I have modified a stored procedure and added an extra parameter to be added to a table. The problem is the value for the added parameter is being swapped with an original parameter.

ALTER PROCEDURE [dbo].[spWeb_BulkGenerateWRsDevices]
(
    @WorkRequestDeviceId nvarchar(max) = NULL,
    @TechnicianId int = NULL,
@RequiredBy  datetime = NULL,
@Priority   int = NULL,
@WRTypeId int,
@WorkRequestSummary nvarchar(255) = NULL,
@AuthorOfRequest   int,
@Contact nvarchar(40) = NULL,
@PhoneNo  nvarchar(20) = NULL,
@StatusId int,
@Created  datetime = NULL,
@CustomerId int
)
AS
/* Update the WR record */
BEGIN
DECLARE @COUNT INT
SET @COUNT =(SELECT COUNT(*) FROM WorkRequest WHERE WorkRequestDeviceId IN(SELECT stringval FROM     dbo.CSV(@WorkRequestDeviceId)))

IF @COUNT >0

BEGIN
DECLARE @InsertedRows AS TABLE (WorkRequestId int,WorkRequestDeviceId int)

INSERT INTO WorkRequest 
(AllocatedTo,RequiredBy,Priority,WRTypeId,WorkRequestSummary,AuthorOfRequest,
    Contact,PhoneNo,StatusId,DateOfRequest,WorkRequestDeviceId,CustomerId)

OUTPUT Inserted.WorkRequestId,Inserted.WorkRequestDeviceId INTO @InsertedRows

     SELECT @TechnicianId ,@RequiredBy,@Priority,@WRTypeId,@WorkRequestSummary,@AuthorOfRequest,@Contact
        ,@PhoneNo,@StatusId,@Created,@CustomerId,* from dbo.fnSplit(@WorkRequestDeviceId, ',')

END

IF @COUNT = 0
BEGIN

INSERT INTO WorkRequest 
(WorkRequestDeviceId)
SELECT * from dbo.fnSplit(@WorkRequestDeviceId, ',')

UPDATE WorkRequest 
SET 
AllocatedTo =@TechnicianId ,
RequiredBy = @RequiredBy,
Priority = @Priority,
WRTypeId = @WRTypeId,
WorkRequestSummary =@WorkRequestSummary,
AuthorOfRequest= @AuthorOfRequest,
Contact = @Contact,
PhoneNo = @PhoneNo,
StatusId = @StatusId,
DateOfRequest = @Created,
CustomerId = @CustomerId
WHERE WorkRequestDeviceId IN(SELECT stringval FROM dbo.CSV(@WorkRequestDeviceId))

END

I have added the CustomerId parameter. When I call the procedure and say set WorkRequestDeviceId = 312 and CustomerId = 148 the table WorkRequest has a new record but with WorkRequestDeviceId = 148 and CustomerId = 312. I am new to stored procedure so sorry for my ignorance, any ideas?
James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:47:19+00:00Added an answer on June 9, 2026 at 6:47 pm

    Your insert is transposing the variables in the insert statement and the select.

    Change your insert to read:

    INSERT INTO WorkRequest 
    (AllocatedTo,RequiredBy,Priority,WRTypeId,WorkRequestSummary,AuthorOfRequest,
        Contact,PhoneNo,StatusId,DateOfRequest,CustomerId,WorkRequestDeviceId)
    

    And all should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a stored procedure that does the following (modified out the data
I have modified my SELECT statement in a stored procedure so that its column
I have a stored procedure which I modified recently on my production server and
I have a stored procedure that cannot be modified , I'm going to stress
How do you pass a table valued parameter to a stored procedure with a
Problem Conditions I have a very simple Oracle (11g) Stored Procedure that is declared
I have a stored procedure called logger(message), where message is of type varchar2. When
I need to have stored procedure where I can run multiple cursors. Loop over
i have to modify a BOOL value in my plist file stored with the
I have a stored procedure that does something like: IF @Param = '1' SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.