Solved

help with nightly update query

Posted on 2013-01-29
5
160 Views
Last Modified: 2013-02-04
Hi experts, I need some help with Nightly updates that I need to do. I need to save some data from queries to files and upload one time and later on daily I should be uploading the new data that is added. The difference of data from Day 1(results from query on Day1) and Day 2(results from query on Day 2).
Please suggest me ways to do it.
thanks
0
Comment
Question by:sqlcurious
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:deviprasadg
Comment Utility
Possible ways :

Solution1:
- Create a table in the database with columns that are fetched by the query, also add the date of execution as a column
- Every day execute the query to populate the table created above (with the date of execution column also populated)
- Also write a query that fetches the difference of data from Day1 and Day2, using the EXCEPT operator.
Sample query:
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() as date)
except
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() -1 as date)

Open in new window


Also be sure to populate executedate with the date(not datetime)
use cast(getdate() as date) while inserting data into this table also.

Solution2:
- BCP Out the query data into files every day.(also you can copy paste into excel and save as CSV)
- Create a two tables in the database with columns that are fetched by the query
   one table can be used for day1 data and other for day2 data.
- BCP in the files that has to be compared into a tables created above.
- Write a query that fetches the difference of data from Day1 table and Day2 table , using the EXCEPT operator.
0
 
LVL 6

Expert Comment

by:liija
Comment Utility
If you need some more control, easier error handling, logging etc. you might use SQL Integration Services package to do the job.
0
 

Author Comment

by:sqlcurious
Comment Utility
For some reason the below logic is not working:
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() as date)
except
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() -1 as date)

I have 7000 records that are different from day1 and day2 but its giving me way way too many, please help
0
 
LVL 10

Accepted Solution

by:
deviprasadg earned 500 total points
Comment Utility
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() as date)
except
SELECT COL1,COL2.. FROM CompareTable where ExecuteDate = cast(getdate() -1 as date)

This query returns any distinct values from the query to the left of the EXCEPT operand that are not also found on the right query.

As you said "7000 records that are different from day1 and day2", you could have come up with this number based on some specific columns that you compared among two result sets.
So use those columns only in the select lists above.

Refer: http://msdn.microsoft.com/en-us/library/ms188055(v=sql.100).aspx

Alternatively you can use Joins or Exists Clause based on the same columns.
0
 

Author Closing Comment

by:sqlcurious
Comment Utility
thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now