Results 1 to 1 of 1
  1. #1
    Join Date
    Dec 2008
    Location
    Ohio
    Posts
    4

    Unanswered: Stored Procedure Help

    Okay I hope I can make sense here. I'm creating a stored procedure as a work around for a project. I have 3 tables, 2 of which have the same "details" field.

    db1 (OPMD_Add_Cost) - details, outage_code, cost
    db2 (OPMD_Add_Scope) - scope (will run as details in sql), outage_code
    db3 (OPMD_Baseline_Creep) - details, outage_code

    I need to make sure all the details[scope] show up upon output to Crystal Reports Datagrid as one cell for each unique outage_code. This is what I have so far. I want to make sure I'm on the right track here. I'm not that familiar with stored procedures.

    Code:
    ALTER PROCEDURE [dbo].[OPMD_Outage_Summary]
    
    AS
    DECLARE @Count INT
    DECLARE @mycount INT
    DECLARE @details varchar(500)
        SET NOCOUNT ON
        SET @mycount = 0
    SELECT @Count = count(*) FROM OPMD_Add_Cost
    CREATE TABLE #Cost
    (Outage_Code varchar(10), Details varchar(500), Cost Integer)
    WHILE @mycount < @Count 
    BEGIN
    INSERT INTO #Cost (Outage_Code, Details, Cost)
    SELECT Outage_Code, Details, Cost
    FROM OPMD_Add_Cost
    SELECT @details = Details
    FROM OPMD_Add_Cost
    SET @mycount = @mycount + 1
    END
    
    DECLARE @scope varchar (500)
        SET NOCOUNT ON
    CREATE TABLE #Scope
    (Outage_Code varchar(10), Scope varchar (500))
    BEGIN
    INSERT INTO #Scope (Outage_Code, Scope)
    SELECT Outage_Code, Scope
    FROM OPMD_Add_Scope
    SELECT @scope = Scope
    FROM OPMD_Add_Scope
    END
    
    DECLARE @details2 varchar (500)
        SET NOCOUNT ON
    CREATE TABLE #Baseline
    (Outage_Code varchar (10), Details varchar (500))
    BEGIN
    INSERT INTO #Baseline (Outage_Code, Details)
    SELECT Outage_Code, Details
    FROM OPMD_Baseline_Creep
    SELECT @details2 = Details
    FROM OPMD_Baseline_Creep
    END
    So basically the output would look ideally like this:

    http://i34.tinypic.com/2rdw3ms.jpg

    and so on. Make sense??
    Last edited by photoshopgrl; 12-16-08 at 10:25.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •