0

看起来数据没有按选择的顺序插入。据我所知,逻辑对我来说看起来不错。现在确定我哪里错了吗?你能帮忙吗?

DECLARE @ReportDate DATE;
    SET @ReportDate = '20130930';
    TRUNCATE TABLE #tmpIntTabel;
    INSERT INTO #tmpCareTabel (
        [SK_ServiceProviderID]
        ,[ReportYear]
        ,[ReportMonth]
        ,[CommissionerCode]
        ,[ServiceProviderName]
        )
        select * from       
        (SELECT DISTINCT tc.SK_ServiceProviderID 
            ,t.Years
            ,t.Months
            ,tc.CommissionerCode
            ,tc.ServiceProviderName
            FROM #TargetClientGroup tc
            INNER JOIN 
            (SELECT
                SK_ServiceProviderID
                ,datepart(yy, dateadd(m, datediff(m, 0, ReportDate), 0)) as Years
                ,datename(mm, dateadd(m, datediff(m, 0,ReportDate), 0)) as Months
                FROM dbo.Component
                WHERE ReportDate <= @ReportDate
                GROUP BY    SK_ServiceProviderID
                            ,ReportDate) t
            on tc.SK_ServiceProviderID = t.SK_ServiceProviderID) a 
    ORDER BY Years
    ,Months
    ,CommissionerCode

插入后,当我选择表格时。我得到无序的数据。

4

1 回答 1

0

尝试这个

ORDER BY t.Years ,t.Months ,tc.CommissionerCode

于 2013-10-04T11:10:13.633 回答