Results 1 to 8 of 8
  1. #1
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22

    Add additional Column based on a column value

    Hi,

    Below is my sample table structure.

    -------------------------------------------------------
    |Name | Type | week1effort | week2effort | week3effort|
    --------------------------------------------------------
    Mr. A | X | 5 | 6 | 2 |
    Mr. A | Y | 7 | 1 | 3 |
    Mr. A | Z | 5 | 6 | 3 |
    Mr. B | X | 4 | 4 | 1 |
    Mr. B | Y | 6 | 2 | 3 |
    Mr. B | Z | 5 | 6 | 6 |

    After uploading this table from excel,


    i should write a query which should give result as follows

    -------------------
    |Name | X | Y | Z |
    -------------------
    Mr.A | 13 |11 |14|
    Mr.B | 9 |11 |17|

    How to achieve this ?
    Thanks in advance.

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check if below gives some guidelines :
    Code:
    TRANSFORM Max(qryTotalEffortA.TotalWeekEffort) AS MaxOfTotalWeekEffort
    SELECT 
    	qryTotalEffortA.testName
    FROM 
    	(
    		SELECT 
    			Table1.testName, 
    			Table1.Type, 
    			Table1.week1effort, 
    			Table1.week2effort, 
    			Table1.week3effort, 
    			[week1effort]+[week2effort]+[week3effort] AS TotalWeekEffort
    		FROM 
    			Table1
    	)
    	AS qryTotalEffortA
    GROUP BY 
    	qryTotalEffortA.testName
    PIVOT 
    	qryTotalEffortA.Type;
    Thanks

  3. #3
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22
    Hi recyan,

    Thanks for the reply
    and sorry for the late response got stuck up with another work..

    This is my query & it throws syntax error..

    transform Max([TABLE1].totalvalue as Max(totalvalue)
    select [TABLE1].[Itemname]
    from (
    select
    [TABLE1].[Itemname],
    [TABLE1].[type],
    [TABLE1].[Effort1],
    [TABLE1].[Effort2],
    [TABLE1].[Effort3],
    [TABLE1].[Effort4],
    [TABLE1].[Effort1]+[TABLE1].[Effort2]+[TABLE1].[Effort3]+[TABLE1].[Effort4] as totalvalue
    from
    [TABLE1])
    as [TABLE1].totalvalue
    group by [TABLE1].[Itemname]
    pivot [TABLE1].[type];

    please revert whare have i made the misatake...thanks in advance..

    Deepan

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Check out below

    Code:
    	
    Transform Max(qryTABLE1.totalvalue as Max(totalvalue)
    select 
    	[TABLE1].[Itemname]
    from 
    	(
    		select
    			[TABLE1].[Itemname],
    			[TABLE1].[type],
    			[TABLE1].[Effort1],
    			[TABLE1].[Effort2],
    			[TABLE1].[Effort3],
    			[TABLE1].[Effort4],
    			[TABLE1].[Effort1]+[TABLE1].[Effort2]+[TABLE1].[Effort3]+[TABLE1].[Effort4] as totalvalue
    		from
    			[TABLE1]
    	)
    	as qryTABLE1
    group by 
    	qryTABLE1.Itemname
    pivot 
    	qryTABLE1.type;
    Thanks

  5. #5
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22
    Hi Recyan,

    Thanks for the quick reply.
    Can you be more specific, what is that qryTable1 ?
    Is it the name of the new query am creating now?

    Thanks,
    Deepan

  6. #6
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Code:
    (
    		select
    			[TABLE1].[Itemname],
    			[TABLE1].[type],
    			[TABLE1].[Effort1],
    			[TABLE1].[Effort2],
    			[TABLE1].[Effort3],
    			[TABLE1].[Effort4],
    			[TABLE1].[Effort1]+[TABLE1].[Effort2]+[TABLE1].[Effort3]+[TABLE1].[Effort4] as totalvalue
    		from
    			[TABLE1]
    	)
    	as qryTABLE1
    qryTABLE1 is the name ( alias ) for the sub query ( shown above) that is there inside your main Query.
    First check if the thing works. Then, if it works ???, read the query slowly. You should get it.

    Thanks

  7. #7
    deepanadhi is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    22
    Thanksalot...
    Got it...now working..

    Thanks a ton for the responses.

    - Deepan

  8. #8
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    H2H - Happy To Help

    Thanks

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

Similar Threads

  1. Replies: 6
    Last Post: 01-13-2012, 09:17 AM
  2. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  3. Replies: 1
    Last Post: 03-14-2011, 10:04 AM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. inserting values in column based another column
    By wasim_sono in forum Database Design
    Replies: 1
    Last Post: 06-27-2006, 05:23 AM

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