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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:52:34+00:00 2026-05-26T08:52:34+00:00

I want to write a t-sql stored procedure (aka sproc) which selects 3 columns

  • 0

I want to write a t-sql stored procedure (aka sproc) which selects 3 columns from ‘MyTable’. In addition, I want to update the table in the same sproc:

  1. I select the third value from the table.
  2. If it equals ‘true’, I want to update the relevant record in the table to ‘false’

I wasn’t sure what syntax should I use. Could you help me out?

ALTER procedure [dbo].[My_PROC]
    @ID varchar(10)
AS
BEGIN

    declare @Col3 bit;

    set @Col3 = select Col3
    from dbo.MyTable  with (nolock)
    where @ID = ID


    if @Col3 = 'true'  
        update dbo.dbo.MyTable set col3 = 'false'
        where @ID = ID

    select Col1, 
    Col2, 
    Col3
    from dbo.MyTable table  with (nolock) where @ID = ID,
    table.Col1,
    table.Col2,
    @Col3   
END

edit: I want to return the original Col3 (not the updated value).

  • 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-05-26T08:52:35+00:00Added an answer on May 26, 2026 at 8:52 am

    Use:

    ALTER procedure [dbo].[My_PROC]
        @ID varchar(10)
    AS
    BEGIN
    
        SELECT t.col1, 
               t.col2, 
               t.col3
          FROM dbo.MyTable AS t WITH (NOLOCK)
         WHERE t.id = @ID
    
        -- No need for an IF statement to determine updating...
        UPDATE dbo.dbo.MyTable 
           SET col3 = 'false'
         WHERE id = @ID
           AND t.col3 = 'true'
    
    END
    

    I don’t know what you’re intending for the final SELECT, but I can update it once I understand what you intended.

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

Sidebar

Related Questions

I want to write a SQL Server 2005 stored procedure which will select and
I have a stored procedure which is returning me about 50 columns. I want
i want to write a stored procedure in java for SQL to parse and
I have to write a Stored Procedure to delete record from a table. I
I want to write an Oracle PL/SQL stored procedure that takes as a parameter
I have a SQL table called StudentMarks.which consist of StudentID,SubjectName,SubjectMark I want to write
I want to write an SQL statement like below: select * from tbl where
I want to write a comparation procedure (t-sql) for site seo. I have a
Question How do I write a T-SQL Stored Procedure that lets me select percentages
I want to write a stored procedure that works something like this: 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.