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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:48:41+00:00 2026-06-05T00:48:41+00:00

I am trying to write a function that increments and returns an int column

  • 0

I am trying to write a function that increments and returns an int column value:

CREATE PROCEDURE [GetNextTagSuffix]
AS
BEGIN

    UPDATE [MyTable]
    SET [NextTagSuffix] = [NextTagSuffix] + 1
    OUTPUT DELETED.[NextTagSuffix]
    WHERE [MyTableId] = 'SpecialCase'

END

The OUTPUT clause can output INTO a table variable or temp table but I just need that single value so adding it first to a table variable seems silly. Is there any way to assign that value directly to a variable and return it?

RESOLVED using table variable:

CREATE PROCEDURE [GetNextTagSuffix]
@TagSuffix int out
AS
BEGIN

DECLARE @tagTable TABLE
(
  NextTagSuffix int
)

UPDATE [MyTable]
SET [NextTagSuffix] = [NextTagSuffix] + 1
OUTPUT DELETED.[NextTagSuffix] INTO @tagTable
WHERE [MyTableId] = 'SpecialCase'

SET @TagSuffix = (SELECT MAX(NextTagSuffix) FROM @tagTable)

RETURN @TagSuffix

END
  • 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-05T00:48:42+00:00Added an answer on June 5, 2026 at 12:48 am

    I believe you have to assign the output to a table variable or temp table. From BOL documentation,

    <OUTPUT_CLAUSE> ::=
    {
        [ OUTPUT <dml_select_list> INTO { @table_variable | output_table } [ ( column_list ) ] ]
        [ OUTPUT <dml_select_list> ]
    }
    

    Note how it specified that the output can be selected into a table variable or table.

    In 2006 a Microsoft Connect action item was filed requesting exactly the functionality you want to use (the ability to do an assignment to a scalar variable from the results of a OUTPUT clause). Microsoft closed the item as “Closed as Won’t Fix”, so for sure this feature was not available in SQL 2005 and was not put into SQL 2008. So unless they had a change of heart, it is not available in SQL 2012 either. You might want to up-vote the connect item or file a new one requesting this feature in a future SQL release.

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

Sidebar

Related Questions

i am trying to write a function that will make DataRow[column] return nullable typed
I am trying to write a function that returns the index of the passed
Trying to write function that numerize items of list and returns list of tuples
I'm trying to write a function that removes a certain value from a linked
I am trying write a function that generates simulated data but if the simulated
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that includes a file named header.php in
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates

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.