Solved

help with nightly update query

Posted on 2013-01-29
5
164 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
ID: 38833929
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
ID: 38834311
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
ID: 38841334
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
ID: 38842420
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
ID: 38852774
thanks
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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