sort order help urgent!!!!!!

  • Hi,

     

    I need to do the following sort order is a parameter to procedure..I have a dynamic sql to do that.After that I group by.Then I need to calculate subtotals for which I use RollUp.

    When I use Roolup my sort order is lost?why is it so?

     

    thanks,

    SSM


    thanx...,

    SSM

  • Can you post the proc code??

    Also why use dynamic sql in this case?

  • CREATE PROCEDURE dbo.prc_indicator_get_machinehours

    @cycleName varchar(50),

    @Framework varchar(50),

    @toolName varchar(50),

    @sortOrder varchar(200)

    AS

    SET ANSI_NULLS OFF

    SET NOCOUNT ON

    declare @sql varchar(5000)

    declare @sort varchar(300)

    set @sort = ""+ @sortOrder +""

    set @sql=''

    set @sql='SELECT [view_machine_hours].[cycleName], [view_machine_hours].[framework], [view_machine_hours].[toolName], [view_machine_hours].[targetName] ,[view_machine_hours].[taskName], [view_machine_hours].[WW], [view_machine_hours].[ExecDate],[view_machine_hours].[ExecHour],[MachineHours]

    FROM [view_machine_hours] where 1=1'

    if @cycleName <> '0'

    begin

     set @sql = @sql + ' and  [view_machine_hours].cycleName like ''%'+ @cycleName + '%'''

    end

    if @Framework <> '0'

    begin

     set @sql = @sql + ' and  [view_machine_hours].framework like ''%'+ @Framework + '%'''

    end

    if @toolName <> '0'

    begin

     set @sql = @sql + ' and  [view_machine_hours].toolName like ''%'+ @toolName + '%'''

    end

    set @sql=@sql + @sort

    print(@sql)

    CREATE TABLE #temp_machine_hours (

     [cycleName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

     [framework] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

     [toolName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

     [targetName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

     [taskName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

     [WW]  [int]  NULL ,

     [execDate] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

     [execHour] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

     [MachineHours] [decimal] (20,10) NULL

    )

    Insert into #temp_machine_hours Exec(@sql)

    SELECT [cycleName], [framework], [toolName],  [targetName],[taskName], [WW], [execDate],[execHour], Sum([MachineHours]) as [MachineHours] FROM #temp_machine_hours

    Group by [cycleName], [framework], [toolName], [targetName] ,[taskName], [WW], [ExecDate],[ExecHour]

    with rollup

    GO


    thanx...,

    SSM

  • How about a create table statement for [view_machine_hours]

    and some example data, and what you want the results to look like.

    http://www.aspfaq.com/etiquette.asp?id=5006

  • REATE VIEW dbo.view_machine_hours

    AS

    SELECT     TOP 100 PERCENT cycleName, framework, toolName, taskName, DATEPART(ww, execDate) AS WW, execDate, execHour,

                          SUM(CAST(StressTime AS decimal) / 3600) AS MachineHours, targetName

    FROM         dbo.tbl_execution_time_hourly

    WHERE     (cycleName IN

                              (SELECT     [tbl_Cycle].[cycleName]

                                FROM          [tbl_Cycle]

                                WHERE      [tbl_Cycle].[deleted] = 0 AND [tbl_Cycle].[dateClosed] IS NULL))

    GROUP BY cycleName, framework, toolName, targetName, taskName, DATEPART(ww, execDate), execDate, execHour

    ORDER BY cycleName, framework, toolName, targetName, taskName, DATEPART(ww, execDate), execDate, execHour

     

     


    thanx...,

    SSM

  • We need to see the expected output too. Help us help you.

  • cycleframeworktooltargettaskweekdatehourmachine hours
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/9/2005160.528611
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/9/2005170.977222
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/9/2005180.983055
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/9/2005190.488055
          6/9/2005 2.97
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/10/2005100.781944
    VFM_Random_PStatediabloDiablo_V1_8sv-pt15summary246/10/2005111.023888
         24  4.78
        summary   4.78
       sv-pt15    4.78
      Diablo_V1_8     4.78
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005110.510555
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005120.9975
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005131.000555
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005140.4175
    VFM_Random_PStatediabloDiablo_V1_8asv-mb33summary276/29/2005160.509166
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005160.780833
    VFM_Random_PStatediabloDiablo_V1_8asv-mb37summary276/29/2005170.965555
    VFM_Random_PStatediabloDiablo_V1_8asv-mb33summary276/29/2005170.983055
          6/29/2005 6.16

     

    something like this..

     

    The problem is I get the table sorted in the order in which is required in the temp table.When I later group by & rollup the temp table,the order is lost.

     

     


    thanx...,

    SSM

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply