+ Reply to Thread
Results 1 to 2 of 2

VBA to Auto update Dates in SQL Query

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBA to Auto update Dates in SQL Query

    Hi Everyone -

    First of all my apologies because I was not even sure how to ask this question. I am trying to automate some analysis we do every month. I am using power query in Excel and queried data from SQL server. As of Right now I have my current period data and prior period data queried from SQL Server. Current period is this month and last month’s data (Mar and Feb). Prior period is Jan and Dec. Everything is working fine and all I wonder if there is any way to include an input command which would directly update the dates, etc. in Power Query SQL code without the need for end user to go into query editor? Usually the fields that we would need to update regularly would be the following:
    a. Dates
    b. Account Number
    I wonder if there could be a VBA code to accomplish this. Hope this makes sense and any help would be greatly appreciated!

    Thanks!!


    Here is the SQL query I used.

    SELECT DISTINCT
    ,[Company]
    ,[Accounting_Month]
    ,[Account_Name]
    ,[Main_Account_Type]
    ,[Reporting_Category]

    FROM [DEP_WTH].[JJ].[Journal]
    WHERE [Company] IN ('5000')
    and [Accounting_Date] Between '2018-10-31' AND '2018-11-30'
    and [Account] = '12345'

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: VBA to Auto update Dates in SQL Query

    I had a co-worker figure this out for me but I haven't had a chance to play with it in depth.

    I have a query that gets model data, but I only want to look at models launched in the last 24 months. So I have this information in a table called Table_Launch_Date.

    Then I have the following code:
    Please Login or Register  to view this content.
    The picture shows the connections.
    Attached Images Attached Images
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 07-20-2018, 11:52 AM
  2. [SOLVED] Update Web Query Without deleting old data, just update new ones.
    By pancho111 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-30-2017, 05:09 PM
  3. Update Query Url: Excel 2016 Query
    By igoodable in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2017, 12:45 PM
  4. Auto update all dates in a column to todays date on workbook open
    By smorri25 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-01-2016, 03:12 AM
  5. Replies: 1
    Last Post: 01-05-2015, 05:39 PM
  6. Auto update pivot table filter dates
    By kaitco in forum Excel General
    Replies: 5
    Last Post: 11-19-2010, 01:40 PM
  7. Changing dates and Auto-Updating sql query
    By brianfitz in forum Excel General
    Replies: 0
    Last Post: 03-23-2009, 11:57 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1