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

  • SEARCH
  • Home
  • 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 7711245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:19:36+00:00 2026-06-01T01:19:36+00:00

I am having a procedure where i need to check the status in the

  • 0

I am having a procedure where i need to check the status in the table which is present in other server and need to update it.

Here is my stored procedure ..please check

ALTER PROCEDURE [dbo].[testproceudre]    
AS       
DECLARE @Status INT     
DECLARE @UpdatedDateTime DATETIME    
DECLARE @STSFLG INT    
--dynamic query variables       

DECLARE @SQLString NVARCHAR(4000)     
DECLARE @ParmDefinition NVARCHAR(4000)     
DECLARE @DBSTRING VARCHAR(1000)     
DECLARE @TABLESTR VARCHAR(200)       
BEGIN     

 SET @DBSTRING = '[server name].[db name]'        
 SET @TABLESTR = ''     

 DECLARE @SYSproUploadflag INT    
 DECLARE @DpCodeExist INT    

 SET @SYSproUploadflag = 0     
 SET @DpCodeExist = 0     
 SET @TABLESTR = @DBSTRING+'.[dbo].[otherservertablename]'     
 SET @ParmDefinition = N'@Status INT,@UpdatedDateTime DATETIME'    
 SET @SQLString ='SELECT StatusFlg,ConfirmedDate FROM localtablename
 JOIN '+ @TABLESTR +' ON     
 IssuesId=SFAIssueId WHERE Statusflg=4'     

 EXECUTE sp_executesql     
 @SQLString,     
 @ParmDefinition,     
 @Status = @Status,     
 @UpdatedDateTime = @UpdatedDateTime     
 BEGIN     
     ------------------------------------------------------------------------  
  IF @SYSproUploadflag = 0     
  BEGIN  
   DECLARE PARKCURSOR CURSOR FOR 
   SELECT STATUS FROM [server name].[db name].[dbo].[otherservertablename]
   JOIN localtablename ON SFAISSUEID = ISSUESID
   OPEN  PARKCURSOR
   FETCH NEXT FROM PARKCURSOR 
   INTO @STSFLG
   WHILE (@@FETCH_STATUS = 0)
   BEGIN
        IF(@STSFLG = 3)
        BEGIN
           UPDATE issue2 SET status = 4,UpdatedDateTime=ConfirmedDate,
           SOURCEOFUPDATION = 'SFA'     
           FROM [server name].[db name].[dbo].[otherservertablename] issue2  JOIN     
           tblAHCIssues issue1    
           ON issue2.sfaissueid=issue1.issuesid 
        END
        IF(@STSFLG = 2)
        BEGIN
           UPDATE issue2 SET status = 7,UpdatedDateTime=ConfirmedDate,
           SOURCEOFUPDATION = 'SFA'     
           FROM [server name].[db name].[dbo].[otherservertablename] issue2  JOIN     
           localtablename issue1    
           ON issue2.sfaissueid=issue1.issuesid  
        END  
        FETCH NEXT FROM PARKCURSOR INTO  @STSFLG 
   END
    CLOSE PARKCURSOR 
    DEALLOCATE PARKCURSOR 
  END     
 END        
END     

My Prob is if the status is 2 in all rows it is updating as 7
if 3 in all rows it is updating as 4
but if some are 3 and some are 2, then the first row what is there , with respect to that only it is updating all the values.that means if 1st row is having status as 3 and second row as 2 it is updating both as 4.but it should update first as 4 and second as 7.can any one help me what mistake i am doing???

  • 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-01T01:19:37+00:00Added an answer on June 1, 2026 at 1:19 am

    There’s no where clause in your update – each of those updates will update exactly the same set of rows (i.e. all those rows in issue2 where there is a matching issue in localtablename).

    This means that the end result will depend on what the last status ID was in your cursor.

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

Sidebar

Related Questions

I am having following stored procedure in my SQL Server 2008 R2 database ALTER
I need to create a sql stored procedure (Sql Server 2008 - T-SQL) which
I'm having trouble with stored procedure here and I'm not sure what to do
Need help speeding up a stored procedure ALTER PROCEDURE [dbo].[yearlynetsales] ( @YearToGet int, @current
I need to develop a SQL Procedure,i am having 2 table one,with following details
I am having the stored procedure. For that i need to pass the Database
I have a weird requirement which I need to use inside my Stored Procedure
I am having a basic mysql stored procedure for inserting user data along with
I am having the below statement from stored procedure. It's giving Insufficient Privileges. But
I'm having some trouble with a stored procedure with a transaction always failing. I

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.