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 7761139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:04:00+00:00 2026-06-01T14:04:00+00:00

Using Microsoft SQL server 2008 I have a query that is in need of

  • 0

Using Microsoft SQL server 2008 I have a query that is in need of some attention.
I’m confused about the joins needed in order to perform my query correctly.

USE [ShaftData]
GO
/****** Object:  StoredProcedure [dbo].[MyPareto]    Script Date: 04/03/2012 19:32:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[MyPareto]
as

SELECT i.pg,
   dbo.OldParetoAnalysis.Pareto,
   i.part,
   i.sumofqty,
   a.sumofqty,
   dbo.NewParetoAnalysis.Pareto

FROM
   OPENQUERY(SACBAUTO, 'SELECT dbo.iLines.Part,
                            dbo.iLines.Pg,
                            SUM(dbo.iLines.Qty) as sumofqty,
                            dbo.iLines.Prefix 
                     FROM Autopart.dbo.iLines 
                     where prefix = ''i''
                     and [datetime] > dateadd(month, -6, getdate())
                     group by 
                     dbo.ilines.pg,
                     dbo.ilines.part,
                     dbo.ilines.prefix
                     order by sumofqty desc') i
RIGHT JOIN
dbo.OldParetoAnalysis
on
i.part collate SQL_Latin1_General_CP1_CI_AS = dbo.OldParetoAnalysis.Part

LEFT JOIN
   OPENQUERY(SACBAUTO, 'SELECT dbo.aLines.Part,
                            dbo.aLines.Pg,
                            SUM(dbo.aLines.Qty) as sumofqty,
                            dbo.aLines.Prefix 
                     FROM Autopart.dbo.aLines 
                     where prefix = ''d''
                     and [datetime] > dateadd(month, -6, getdate())
                     group by 
                     dbo.alines.pg,
                     dbo.alines.part,
                     dbo.alines.prefix
                     order by sumofqty desc') a
ON
dbo.OldParetoAnalysis.Part collate SQL_Latin1_General_CP1_CI_AS = a.part
FULL JOIN
dbo.NewParetoAnalysis
ON
a.part collate SQL_Latin1_General_CP1_CI_AS = dbo.NewParetoAnalysis.Part
WHERE
i.pg = '31'
GROUP BY
   i.pg,
   dbo.OldParetoAnalysis.Pareto,
   i.part,
   i.sumofqty,
   a.sumofqty,
   dbo.NewParetoAnalysis.Pareto
ORDER BY
dbo.OldParetoAnalysis.Pareto desc

Ok the explanation, I need to show those fields. Currently I need all the rows from old pareto to show. new pareto is a clone of the old one that will be used for updating (thats the next part thats planned).

The problem have is that currently my pareto is showing correclty 1-5780. but the new pareto column that should match row for row is showing blanks, this suggests that not all rows are being shown (possibly something to do with Nulls).

I hope its something to do with my joins, as you can see its probably an overcomplicated query, but it works for what I need, problem is the time, its rushed because I have 24 hrs to complete this query with no prior planning (yes I face palmed as well).

Oh and Pareto is just a number assigned to the best selling parts, like a league.

If you require any more info just ask and ill edit.

Many thanks

EDIT:
Ok solved the problem, the answer will be updated.

I have got very confused, can someone show me how I would now Update my old and new pareto tables? since theres a ton of joins

  • 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-06-01T14:04:01+00:00Added an answer on June 1, 2026 at 2:04 pm

    heres the Code:

    USE [ShaftData]
    GO
    /****** Object:  StoredProcedure [dbo].[MyPareto]    Script Date: 04/04/2012 08:50:40 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER PROCEDURE [dbo].[MyPareto]
    @pgParam varchar(255)
    AS
    SELECT i.pg,
       dbo.OldParetoAnalysis.Pareto,
       i.part,
       i.sales6months,
       a.LostSales6Months,
       dbo.NewParetoAnalysis.Pareto
    
    FROM
    OPENQUERY(SACBAUTO, 'SELECT dbo.iLines.Part,
                                dbo.iLines.Pg,
                                SUM(dbo.iLines.Qty) as sales6months,
                                dbo.iLines.Prefix 
                         FROM Autopart.dbo.iLines 
                         where prefix = ''i''
                         and [datetime] > dateadd(month, -6, getdate())
                         group by 
                         dbo.ilines.pg,
                         dbo.ilines.part,
                         dbo.ilines.prefix
                         order by sales6months desc') i
    RIGHT JOIN
    dbo.OldParetoAnalysis
    on
    i.part collate SQL_Latin1_General_CP1_CI_AS = dbo.OldParetoAnalysis.Part
    INNER JOIN
    dbo.NewParetoAnalysis
    ON
    dbo.OldParetoAnalysis.Part collate SQL_Latin1_General_CP1_CI_AS = dbo.NewParetoAnalysis.Part
    
    LEFT JOIN
    OPENQUERY(SACBAUTO, 'SELECT dbo.aLines.Part,
                                dbo.aLines.Pg,
                                SUM(dbo.aLines.Qty) as LostSales6Months,
                                dbo.aLines.Prefix 
                         FROM Autopart.dbo.aLines 
                         where prefix = ''d''
                         and [datetime] > dateadd(month, -6,   getdate())
                         group by 
                         dbo.alines.pg,
                         dbo.alines.part,
                         dbo.alines.prefix
                         order by LostSales6Months desc') a
    ON
    dbo.NewParetoAnalysis.Part collate SQL_Latin1_General_CP1_CI_AS = a.part
    /*FULL OUTER JOIN
    dbo.NewParetoAnalysis
    ON
    a.part collate SQL_Latin1_General_CP1_CI_AS = dbo.NewParetoAnalysis.Part*/
    WHERE
    i.pg = @pgParam
    GROUP BY
       i.pg,
       dbo.OldParetoAnalysis.Pareto,
       i.part,
       i.sales6months,
       a.LostSales6Months,
       dbo.NewParetoAnalysis.Pareto
    ORDER BY
    dbo.OldParetoAnalysis.Pareto asc
    

    Now i have a new question.
    Using c sharp, how would i update the Old and New pareto tables?

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

Sidebar

Related Questions

I'm using SQL Server 2008 R2 and Microsoft Excel. I have the server set
I have a website using Microsoft SQL 2008 server over local network. Sometimes, SQL
I am using T/SQL in Microsoft SQL Server 2008 I have a table CREATE
I have been using SQL Server 2008 for about a year now and my
I am using Esri ArcMap 10.0 with Microsoft Sql Server 2008 R2 I have
I am using Microsoft SQL Server 2008. I have a stored procedure. Is there
Using Microsoft SQL Server 2008. I have a table of interest rates. I've manually
I am using Microsoft SQL Server 2008. I have a very large text file
Using: Microsoft SQL Server 2008 Microsoft Visual Studio 2010 C# .NET 4.0 WinForms Ok
I'm using Microsoft SQL Server 2008 Management Studio to create a relational schema by

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.