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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:10:09+00:00 2026-05-31T12:10:09+00:00

Okay, say i have a table with the field code. The query select code

  • 0

Okay, say i have a table with the field “code”. The query select code from mytable group by code returns:

code
EM010
EM100
EM101
EM105
EM106
...

I need to add a column (with a join or something) that will contain the next highest code. The above would turn to:

code    code2
EM010   null (or blank or wtvr)
EM100   EM010
EM101   EM100
EM105   EM101
EM106   EM105
...     ...

I’d provide what I’ve tried but it’s messy and I keep realizing I’m going about it the wrong way.

btw, i’m working in vfp so it’s technically tsql but i should be able to convert anything that’s different, so i don’t mind if i get answers that haven’t been tested in tsql.

  • 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-31T12:10:11+00:00Added an answer on May 31, 2026 at 12:10 pm

    Try

    DECLARE @T TABLE (Code VARCHAR(5))
    INSERT @T VALUES ('EM010'), ('EM100'), ('EM101'), ('EM105'), ('EM106')
    
    SELECT  T1.Code,
            (   SELECT  MAX(Code)
                FROM    @T t2
                WHERE   t1.Code > t2.Code
            ) AS Code2
    FROM    @T t1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so my question is this. Say I have a simple C++ code: #include
Okay, so let's say I have a mysql database table with two columns, one
For example I have the following tables resulting from: CREATE TABLE A (Id int,
Okay, I'll simplify this post. I have a table tasks containing, for example, a
Okay say I have a function like below: -(NSNumber *)calculate{ NSNumber *myNum = [[[NSNumber
Okay, so let's say I have a class file called Orange, and then two
Okay, let's say we have a class defined like public class TestClass { private
Okay say I have two timestamps saved in database in the format yyyymmdd, a
Okay lets say I have a list, and I want to check if that
Okay. Say I have string '193' And I want to remove the last numbers

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.