Jump to content

Allocate ID based on records


Curt_38

Recommended Posts

Hi everyone, first time poster. Hope this is ok.

 

I have a table that has 100's of car records. I am creating a form where the dropdown list option selected will sort them into groups of 4 cars based on their year and make. After this the groups will need to have a group id (For example NIS1101). The first 3 letters are the make of the car, first two numbers are the year and the last numbers are the group number. Hope this isn't confusing.
 
How would you sort and allocate a group id to each group? Would it be best to ORDER BY or GROUP BY then make a function to allocate this id? I'm not sure how I would go about this.
 
I appreciate any help I could get. Thanks in advance
 
CREATE TABLE cars
(
CarID int (10),
Make varchar (255),
Model varchar(255),
Year varchar(4),
EngineSize varchar ( 8),
); 
Example Data

  CarID    ,   Make   ,   Model   ,   Year   ,   EngineSize   
  16528454,   Toyota,     Prius,      2007          1.8
  45619810,   Toyota,     AE-86,      2012,         2.0
  32541811,   Nissan,     Skyline,    2008,         3.0
  25856181,   Mitsubishi, Nimbus,     2000,         2.4
  29519815,   Toyota,     Celica,     2007,         1.8
  16916598,   Holden,     Barina,     2011,         1.6
  65619818,   Mitsubishi, Evolution,  2008,         2.4
  15616518,   Holden,     Commoodore, 2011,         6.0

Group Data (based on group of 4)

  GroupID   ,   Make   ,   Model   ,   Year   ,   EngineSize   
  TOY101,     Toyota,     Prius,        2013,         1.8
  TOY101,     Toyota,     AE-86,        2013,         2.0
  TOY101,     Toyota,     Celica,       2013,         1.8  
  TOY101,     Toyota,     Prius,        2012,         1.8
  TOY102,     Toyota,     AE-86,        2012,         2.0  
  TOY102,     Toyota,     Celica,       2012,         1.8
  NIS201,     Nissan,     Skyline,      2013,         3.0
  NIS201,     Nissan,     Skyline,      2013,         3.0
  NIS201,     Nissan,     Silvia,       2013,         2.0
  NIS201,     Nissan,     Skyline,      2013,         3.0
  NIS202,     Nissan,     Pulsar,       2013,         2.0
  NIS202,     Nissan,     Skyline,      2012,         3.0
  NIS202,     Nissan,     Pulsar,       2009,         2.0
  NIS202,     Nissan,     Skyline,      2008,         3.0
  MIT301,     Mitsubishi, Nimbus,       2012,         2.4
  MIT301,     Mitsubishi, Evolution,    2013,         2.4
  MIT301,     Mitsubishi, Nimbus,       2012,         2.4
  MIT301,     Mitsubishi, Evolution,    2008,         2.4
  HOL401,     Holden,     Barina,       2013,         1.6
  HOL401,     Holden,     Commoodore,   2012,         6.0
  HOL401,     Holden,     Barina,       2011,         1.6
  HOL401,     Holden,     Commoodore,   2011,         6.0
  HOL402,     Holden,     Barina,       2010,         1.6
  HOL402,     Holden,     Commoodore,   2007,         6.0

 

Link to comment
Share on other sites

 

 

The first 3 letters are the make of the car, first two numbers are the year and the last numbers are the group number. Hope this isn't confusing.

 

It becomes totally confusing once one looks at your sample group ids, which bear little resemblance to to your description of the id structure

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.