Advertisement

09.14.2007 at 05:37AM PDT, ID: 22828650
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Help needed with complex INSERT SQL on SQL Server 2000

Tags: insert, complex, sql, statement
Fellow Experts,

I need your help with a SQL batch (SQL Server 2000) to run first a delete and then an insert.

The relevant tables/columns:



volume
------------------------------------------------------
volume_id (uniqueidentifier, PK)
activity_code (char(20))
work_center_code (varchar(50))

volume_detail
------------------------------------------------------
volume_id (uniqueidentifier, PK)
sample_date (datetime, PK)
sample_value (real)


volume_detail has transaction volumes for half-hour time increments for a given
work center and activity code.  I need to do the following:

1) Delete all records from volume_detail where the related activity code is 'TlrTot'
and the sample date is >= 1 Jan 2007.  This SQL should do the trick:

DELETE volume_detail
FROM volume_detail INNER JOIN
    volume ON volume.volume_id = volume_detail.volume_id
WHERE volume.activity_code = 'TlrTot'

2) Insert new records into volume_detail such that for every record returned by the query below,
we insert one record into volume_detail with the appropriate volume_id.

SELECT v.work_center_code, 'TlrTot' AS activity_code, vd.sample_date, SUM(vd.sample_value) AS sample_value
FROM volume_detail INNER JOIN
    volume ON volume.volume_id = volume_detail.volume_id
WHERE v.activity_code LIKE 'T-V01%'
GROUP BY v.work_center_code, 'TlrTot', vd.sample_date
HAVING vd.sample_date >= '1 Jan 2007'


So, Experts, please have a look at my DELETE statement and let me know if it looks proper, and
please have a go at writing the INSERT statement.  Your help is very, very much appreciated.

Regards,

Patrick
Start your free trial to view this solution
Question Stats
Zone: Database
Question Asked By: matthewspatrick
Solution Provided By: ptjcb
Participating Experts: 3
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
09.14.2007 at 06:43AM PDT, ID: 19891338

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 06:56AM PDT, ID: 19891470

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 06:59AM PDT, ID: 19891502

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:33AM PDT, ID: 19891857

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:38AM PDT, ID: 19891919

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:48AM PDT, ID: 19892014

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:57AM PDT, ID: 19892095

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 07:58AM PDT, ID: 19892110

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 08:04AM PDT, ID: 19892166

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 08:07AM PDT, ID: 19892203

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:36AM PDT, ID: 19893551

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:43AM PDT, ID: 19893608

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.14.2007 at 10:46AM PDT, ID: 19893625

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_1_20070628