Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3976168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:46:20+00:00 2026-05-20T04:46:20+00:00

I’m not sure if this is practically possible with SQL (I’m using MS SQL

  • 0

I’m not sure if this is practically possible with SQL (I’m using MS SQL 2005) but what I’m trying to do is to create a summary table of customer transactions which would be updated weekly or so – a very simplified version of this would look like this:

+-----------------+----------------+----------------+----------------+----------------+
+   Customer_id   + 2007 purchases + 2008 purchases + 2009 purchases + 2010 purchases +
+-----------------+----------------+----------------+----------------+----------------+
+   id_001        +       0        +       7        +       10       +       50       +
+-----------------+----------------+----------------+----------------+----------------+
+   id_002        +       0        +       0        +       5        +       20       +
+-----------------+----------------+----------------+----------------+----------------+
+   id_003        +       100      +       0        +       0        +       0        +
+-----------------+----------------+----------------+----------------+----------------+

Within my table I have around 7 million customers so I don’t want to have to recreate this each week if their data hasn’t changed within the last week.

Ideally I would like to determine whether or not customer purchase data has changed since the last time the stored procedure was run (and i would only be interested in cases where there has been a new purchase since running that named procedure, therefore ignoring all other ones), and then only apply the update statement to those customers.

I was thinking along the lines of doing something like applying this as a filter:

WHERE EXISTS (SELECT customer_id 
FROM purchases WHERE DATEADD(dd, 0, DATEDIFF(dd, 0, purchase_date)) > DATEADD(dd, -8, DATEDIFF(dd, 0, getdate()))

To pick up new purchases within the last week, but if the frequency of the stored procedures changes, this will need to be altered as well, so if I can filter for records only updated since last occurence of the stored procedure that would be best!

Thanks!

Actual Table Structure – simplified

CREATE TABLE
(
id UNIQUEIDENTIFIER
,customer_id NVARCHAR(255)
,date_received DATETIME
,value DECIMAL(18,3)
)

So I am using what amount to a pivot query to include information for each year for each customer in the sample table above (which works fine) and is part of a more complex query. The query is quite slow when applied to all customers, and so I’m fundamentally looking for a way to only run it within a stored procedure if the output is going to differ from what’s already in the table!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:46:21+00:00Added an answer on May 20, 2026 at 4:46 am

    why don’t you just store the date when the report is run? that way your query doesn’t have to change, you just take the difference between ‘today’ and the last time the stored proc was run.

    edit I would add another table to the database where you simply store the date when you run the report. you can simply populate this table from the code that requests the report, or from the stored procedure that generates it. However, you may not need the entire history of report runs, so you might be able to get away with storing just the last date when the report was run (this would obviously also save you some space in the database).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I'm looking for suggestions for debugging... If you view this site in Firefox or
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
In order to apply a triggered animation to all ToolTip s in my app,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.