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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:26:08+00:00 2026-06-03T09:26:08+00:00

Ok so I have a table where we have custid, lastname, firstname, and DOB.

  • 0

Ok so I have a table where we have custid, lastname, firstname, and DOB.

My task is to create one more column with the string that gives the decade the customer was born…

i.e. if the cust was born in 1950, the new colum for that record should say, Fifties,
If the cust was born in 1974, the new column for that record should say, Seventies. and so on.

I think I have to group by each decade and make a new column that gives the “string” representation of the decade the cust was born.

This is my try…

Select DateOfBirth, COUNT(DateOfBirth) as 'DOBYEAR' From Customers
Group by DateOfBirth
Order By DateOfBirth asc
If (Customers.DateOfBirth <= '1979')
begin
set DOBYEAR = 'Seventies and Before'
end
If (Customers.DateOfBirth between '1980' and '1989)'
begin
set DOBYEAR = 'Eighties'
end
If (Customers.DateOfBirth between '1990' and '1999')
begin
set DOBYEAR = 'Nineties'
end
If Customers.DateOfBirth >= '2000'
Begin
set DOBYEAR = '20th century'
end
Go

I am creating DOBYEAR as the new column and trying to input strings like, “seventies and before, eighties, nineties, and 20th century….

gives me the following error.

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Line 14
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Line 18
Incorrect syntax near '='.

Please guide me in the right direction.

Can I use “Print ‘Seventies and Before'” instead of “set DOBYEAR = ‘Seventies and Before'”?

Maybe, I can do this without using IF statements but do not know how.

ThankX

  • 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-03T09:26:09+00:00Added an answer on June 3, 2026 at 9:26 am

    You don’t need group by to do this. Assuming the DateOfBirth column is type datetime (hint: it should):

    Select 
        DateOfBirth, 
        Case 
          when datepart(year, DateOfBirth) between 1970 and 1979 then 'Seventies' 
          when datepart(year, DateOfBirth) between 1980 and 1989 then 'Eighties' 
          when datepart(year, DateOfBirth) between 1990 and 1999 then 'Nineties' 
          when datepart(year, DateOfBirth) >= 2000 then '21st century' 
          else 'Before 1970' 
        end as DOBDecadeString
    From 
       Customers
    Order By DateOfBirth asc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have customer table which has record CustId LastName 1 Hamlin In one
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
SQL Query: CREATE TABLE mytbl.customer( CustID int( 10 ) NOT NULL AUTO_INCREMENT , FirstName
I have table with around 70 000 rows. There is 6000 rows that i
I have table and this table contain result column with some entries. I just
I have table of data that is sorted as follows: Item | Sample |
I have a table in a with the following structure: CustID --- DateAdded ---
I have a table that I am drawing information on that has a few
i have NSTableView and two columns in it: NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@custId]
The situation is, that i need to create table in grid view looking like

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.