Results 1 to 6 of 6
  1. #1
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46

    Append SQL Statement expression

    INSERT INTO [WeeklySalesTrending-CW] ( Location, Store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 )
    SELECT [qryWeekOverWeekSales-CurrentYear].Location, Left([location],Len([location])-9) AS Store, [qryWeekOverWeekSales-CurrentYear].[1] AS Expr1, [qryWeekOverWeekSales-CurrentYear].[2] AS Expr2, [qryWeekOverWeekSales-CurrentYear].[3] AS Expr3, [qryWeekOverWeekSales-CurrentYear].[4] AS Expr4, [qryWeekOverWeekSales-CurrentYear].[5] AS Expr5, [qryWeekOverWeekSales-CurrentYear].[6] AS Expr6, [qryWeekOverWeekSales-CurrentYear].[7] AS Expr7, [qryWeekOverWeekSales-CurrentYear].[8] AS Expr8, [qryWeekOverWeekSales-CurrentYear].[9] AS Expr9, [qryWeekOverWeekSales-CurrentYear].[10] AS Expr10, [qryWeekOverWeekSales-CurrentYear].[11] AS Expr11, [qryWeekOverWeekSales-CurrentYear].[12] AS Expr12, [qryWeekOverWeekSales-CurrentYear].[13] AS Expr13, [qryWeekOverWeekSales-CurrentYear].[14] AS Expr14, [qryWeekOverWeekSales-CurrentYear].[15] AS Expr15, [qryWeekOverWeekSales-CurrentYear].[16] AS Expr16, [qryWeekOverWeekSales-CurrentYear].[17] AS Expr17

    FROM [qryWeekOverWeekSales-CurrentYear];


    This is my sql statement that appends a table of which i have field names in table WeeklySalesTending-CW, location,Store, fields for 53 weeks



    My question is how can I have sql to append to 53 weeks and maybe a null statement if only at week 20. Right now I have to edit the shaded sections and add a week each week, and add expr week because of my query( qryWeekOverWeeK-CurrentYear) sql listed below

    SQL for this query:

    TRANSFORM Sum(CCur([Net_Sales])) AS Sales
    SELECT [Store]+"-"+"Cur Year" AS Location
    FROM (qryWeeklySales LEFT JOIN tblStore ON qryWeeklySales.Store_Id = tblStore.StoreId) LEFT JOIN tblStoreReference ON tblStore.StoreRef = tblStoreReference.Ref_No
    WHERE (((qryWeeklySales.year)=(Year(Date()))) AND ((tblStoreReference.Status) Is Null Or (tblStoreReference.Status)<>"CLD"))
    GROUP BY [Store]+"-"+"Cur Year"
    ORDER BY [Store]+"-"+"Cur Year", qryWeeklySales.Week_Number DESC
    PIVOT qryWeeklySales.Week_Number;

    It works now but I have to add red part in sql four times for four different queries I designed like above.

    thanks
    Last edited by Jgk; 05-15-2014 at 10:42 PM. Reason: edit

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You have fields named 1, 2, 3, 4, ... 53?
    That is not a normalized data structure. Why are you saving non-normalized data?

    Note that the & character is the preferred concatenation operator.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Databases like to store data top-down, not left-to-right.

    It would be:
    [STORE#],[WEEK], [SALES AMT].

  4. #4
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46
    Importing data from micros pos to access and creating excel report comparing weeks, I have 4 tables with weeks 1-53, location, and store to save thru append queries like above

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Same question. Why save non-normalized data? Just save raw data then manipulate with queries for desired output.

    Forcing the CROSSTAB to produce fields for the future weeks where there is no data would be tricky at best, certainly not easy.

    Also, I would think only 1 table is necessary with another field for the store ID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Jgk is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    46
    I save data to table raw data n manipulate with 4 queries saving to four tables

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

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2014, 11:10 AM
  2. Run Append Query From If Statement
    By scoe in forum Queries
    Replies: 2
    Last Post: 04-02-2014, 07:41 AM
  3. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  4. Append Query with IIF statement
    By Cheshire101 in forum Queries
    Replies: 5
    Last Post: 09-16-2010, 12:51 PM
  5. Replies: 1
    Last Post: 03-23-2010, 04:01 PM

Tags for this Thread

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