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

  • Home
  • SEARCH
  • 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 7735889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:36:47+00:00 2026-06-01T07:36:47+00:00

Using: Microsoft SQL Server 2008 Microsoft Visual Studio 2010 C# .NET 4.0 WinForms Ok

  • 0

Using:

  • Microsoft SQL Server 2008
  • Microsoft Visual Studio 2010
  • C#
  • .NET 4.0
  • WinForms

Ok this is my stored procedure. Brace yourself, it’s rushed because I have a deadline of 24 hrs and I was told yesterday as I was leaving work (yes I was very annoyed).

SET ANSI_NULLS ON
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

Procedure works great, pretty fast too (no idea how hehe). The problem I now have is how to update.

I only want to update 2 tables: OldPareto and NewPareto.

The data will only come from one column which is the NewPareto column. This will update the column in both tables.

Normally its just a simple UPDATE call in the code using the SqlDataAdapter and DataSet.

But since I have this crazy stored procedure I’m troubled as to how this works.

Any C# code you need let me know.

Many thanks!

  • 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-01T07:36:48+00:00Added an answer on June 1, 2026 at 7:36 am

    A long winded way would be too get the new pareto into a new table in
    my code, then use the table to update my 2 sql tables

    Or in sql procedure itself. I still do not understand what are your objects and their relationships, but here is general way to perform similar updates:

    First declare temporary table at the beginning of procedure:

    declare @tmpTable table 
    (
      pg int, 
      oldPareto int, 
      part int, 
      sales6months int, 
      LostSales6Months int,
      newPareto int
    )
    

    obviously, column types do not match yours so you will need to type them properly.
    Perform insert into using your select:

    insert into @tmpTable 
         (pg, oldPareto, part, sales6months, LostSales6Months, newPareto)
         select ...
    

    And then perform updates:

    update oldPareto
       set oldPareto = a.oldPareto,
           newPareto = a.newPareto
      from oldPareto
        inner join @tmpTable a
           on ... -- However you join oldPareto table with results of query
    
    update newPareto
       set oldPareto = a.oldPareto,
           newPareto = a.newPareto
      from newPareto
        inner join @tmpTable a
           on ... -- However you join newPareto table with results of query
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Microsoft SQL Server 2008 Management Studio to create a relational schema by
I'm using Visual Studio 2008, and my database is SQL Server 2000. I want
Using Microsoft SQL server 2008 I have a query that is in need of
I'm using SQL Server 2008 R2 and Microsoft Excel. I have the server set
I am trying to create an add-in by using the article below http://blogs.microsoft.co.il/blogs/shair/archive/2008/07/28/how-to-create-sql-server-management-studio-addin.aspx I
I'm using Microsoft SQL Server Management Studio to work with a database. I'm only
I'm using VB.NET and Microsoft SQL Server 2005 to create an application. I was
I recently installed Visual Studio 2010 and SQL Server 2012 on a Windows Server
Using Microsoft SQL Server 2008, let's say there is a table1 that keeps the
I'm using Microsoft SQL Server 2008. I'm not an expert with it but I

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.