Results 1 to 6 of 6
  1. #1
    JEEVAN34 is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    10

    Create a sepearte column baesd on the data in other columns

    Hi! I have a database with all the countries and thier states Information. I Need to write a query to a create a new column(Shortcut) specifying C/S for each Country first line and only S for other lines. Refer to the attachments
    Attached Thumbnails Attached Thumbnails pic.JPG   pic2.JPG  

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    it can be done, but you need a column to indicate which is first - you cannot rely on the order in which it is displayed (which is an excel attribute) to determine first.

    From your example this would appear to be the GDP2 column. Assuming this is the case then a query like this would do the job

    Code:
    SELECT O.*, iif(F.gdp2 is null,"S","C/S") as Shortcut
    FROM tblCountries O 
        LEFT JOIN 
            (SELECT Country, max(GDP2) FROM tblCountries GROUP BY Country) F 
                ON O.Country=F.Country AND O.GDP2=F.GDP2

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    no. You may do it in a table, but not in a query.

  4. #4
    JEEVAN34 is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    10
    hello Ajax,
    Thanks for your suggestion. But i need to create a new column based on Countries and Cities columns. Is it possible??

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    As ranman says, if you want to create a new column you would need to add the new column to the table either manually, through tabledefs or use sql - see this link

    My suggested query was based on country and gdp2. Not sure about cities, do you mean states? either way you would still need some definition of order to determine 'first'. You cannot base it purely on the first one in the list since this is random.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    hit the wrong button! -- Sql link

    http://www.w3schools.com/sql/sql_alter.asp

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-12-2016, 07:15 AM
  2. Replies: 2
    Last Post: 10-26-2015, 06:14 AM
  3. Replies: 3
    Last Post: 03-02-2015, 09:50 AM
  4. Replies: 1
    Last Post: 11-12-2013, 02:19 AM
  5. Replies: 5
    Last Post: 03-29-2012, 09:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums