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 8841509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:44:09+00:00 2026-06-14T10:44:09+00:00

I am writing a sql proc with two parameters: @id and @id_group. Consider this

  • 0

I am writing a sql proc with two parameters: @id and @id_group.

Consider this table group_info

ID   ID_Group    SupercededBy   Superceded   status
1    1           null           null         H
2    1           null           null         U

Given these parameters:

@id = 2
@id_group = 1

The first thing I need to do is to set the row’s SupercededBy to @id, where ID=@id and id_group=@id_group and status='H'.

Here is the statements I have written:

  update group_info
      set supercededby = @id
      where id_group=@id_group and status='H'

The second thing I need to do is to set the row’s Superceded to the id whose SupercededBy has been just updated from the above statements.

So in this example, row 2’s Superceded should be updated to 1.

But how to write the statements? I guess the statements might be something like this:

update group_info
      set superceded = **old_id**
      where id=@id

I know how to get the old_id, here it is

select id
    from group_info
    where id_group=@id_group and status='H'

But how can I use the values in the above select and insert the value to the update statements as old_id?

The final table should be

ID   ID_Group    SupercededBy   Superceded   status
1    1           2              null         H
2    1           null           1            U

I am using MS SQL Server.

  • 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-14T10:44:11+00:00Added an answer on June 14, 2026 at 10:44 am

    A SELECT @variable = columnName FROM ... statement can be used like this:

    DECLARE @oldId INT
    
    select @oldId  = id
        from group_info
        where id_group=@id_group and status='H'
    
    update group_info
          set superceded = @oldId 
          where id=@id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a SQL Stored Proc which takes in a single table valued
So, I'm writing this Stored Proc and I really suck at SQL. My Question
I am new to writing SQL and would greatly appreciate help on this problem.
I'm writing a SQL embedded in C program with tables below: table index:id, xx
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
I'm writing sql to search a database by a number of parameters. How would
Given the premise: There are competent sql programmers (correlary - writing sql queries are
I'm writing a stored proc in SQL Server 2008. The following code: SELECT @LastAccessed
I'm writing sql query to get post and only last comment of this post(if
I have a doubt in writing sql. I had a farmerfields table with YEAR,SEASON,Number

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.