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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:30:19+00:00 2026-06-07T00:30:19+00:00

I want to create a new field (or two) in my table that is

  • 0

I want to create a new field (or two) in my table that is a concatenation of other fields, which seems relatively straightforward. But what is the case syntax or if/when syntax I’d use to help create the following fields (GPA_TXT, and newfield)?

The logic is: Each GPA should be #.#, each new field should be:

name & "-" & GPA_TXT & (
    case where GPA_TXT > 3.3
        set newfield = newfield & 'GradeA',
    case where GPA_TXT >2.7 and GPA_TXT < 3.3
        set newfield = newfield & "GradeB",
    etc...
)

For example:

name         major     GPA(num) GPA_TXT   [newfield]
Bob          sci       2        02.0      Bob-sci-GradeC-02.0
Jane         chem      3.1      03.1      Jane-chem-GradeB-03.1
Charlie      phys      3.7      03.7      Charlie-phys-GradeA-03.7
Garfield     food      0        00.0      Garfield-food-GradeF-00.0

So I guess I have two questions in here:

  1. How to create the GPA TXT field.
  2. How to write a case statement to calculate a field according to the values in other fields.

If anyone can link me to a resource with examples or explain I would greatly appreciate it! I’m looking through the documentation but not getting anywhere without examples.

  • 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-07T00:30:20+00:00Added an answer on June 7, 2026 at 12:30 am

    Important note: I would create a view based on your current table and avoided adding new columns, as they will denormalize your schema. Read more here.

    Also, I will use lowercase names for all the identifiers to avoid qouting.

    • to form GPA_TXT field you can use to_char() function: to_char(gpa, 'FM09.0') (the FM will avoid space in front of the resulting string);
    • for the second field, I would use GPA and not GPA_TXT for numeric comparison. You can check more on CASE construct in the docs, but the block might be the following one:

      CASE WHEN gpa >= 3.3 THEN 'A'
           WHEN gpa > 2.7 AND gpa < 3.3 THEN 'B'
           WHEN gpa > 0 THEN 'C'
           ELSE 'F' END
      

    Sorry, I don’t know how grades are assigned per GPA, please, adjust accordingly.

    The resulting query for the view might be (also on SQL Fiddle):

    SELECT name,major,gpa,
           to_char(gpa, 'FM09.0') AS gpa_txt,
           name||'-'||major||'-Grade'||
      CASE WHEN gpa >= 3.3 THEN 'A'
           WHEN gpa > 2.7 AND gpa < 3.3 THEN 'B'
           WHEN gpa > 0 THEN 'C'
           ELSE 'F' END || '-' || to_char(gpa, 'FM09.0') AS adesc
      FROM atab;
    

    To build a view just prepend CREATE VIEW aview AS before this query.


    EDIT

    If you still go for adding columns, the following should do the trick:

    ALTER TABLE atab ADD gpa_txt text, ADD adesc text;
    UPDATE atab SET
        gpa_txt = to_char(gpa, 'FM09.0'),
        adesc = name||'-'||major||'-Grade'||
          CASE WHEN gpa >= 3.3 THEN 'A'
               WHEN gpa > 2.7 AND gpa < 3.3 THEN 'B'
               WHEN gpa > 0 THEN 'C'
               ELSE 'F' END || '-' || to_char(gpa, 'FM09.0');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new record in the mailers table, where three fields
I want to create a new project in Xcode (4.2), but I don't need
I want to create one new model class, which will be extended in all
i want to create a join between two tables and that the result will
i've two table in DB. i want to create dropdownlist for city and corresponding
I want to create new WCF service and client. The 2 parties will communicate
I want to create new creative and check its audit status in facebook ads
I want to create new node of BeanTreeView, and when I add some node
I'm using SharePoint 2010. I want to create new view for my list. The
I want to create a new custom control derived from ContentControl (it will be

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.