Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help with nightly update query

Posted on 2013-01-29
5
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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 I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

718 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