查询每次运行返回不同的结果 [英] Query returns a different result every time it is run

查看:27
本文介绍了查询每次运行返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此查询总是返回相同数量的行,但每次都以不同的顺序返回.为什么会发生这种情况?

This query always returns the same amount of rows but, in a different order, every time. Why does this happen?

我有更多过滤器要添加,但我无法通过这一步.

I have more filters to add but I can't get past this step.

BEGIN
DECLARE @lastStatus Varchar(10)
SELECT
    [Job].[Job],
    [Job].[Part_Number],
    [Job].[Rev],
    [Job_Operation].[Description],
    [Job].[Customer_PO],
    [Job].[Customer_PO_LN],
    [Delivery].[Promised_Date],
    [Job_Operation].[Operation_Service],
    [Job].[Note_Text],
    [Job_Operation].[Status],
    [Job_Operation].[Sequence]
INTO [#tmpTbl]
FROM [PRODUCTION].[dbo].[Job_Operation]
    INNER JOIN [Job]
        ON [Job_Operation].[Job]=[Job].[Job]
    INNER JOIN [Delivery]
        ON [Job_Operation].[Job]=[Delivery].[Job]
WHERE [Job].[Status]='Complete'
ORDER BY [Job_Operation].[Job],[Job_Operation].[Sequence]
SELECT *
FROM [#tmpTbl]
DROP TABLE [#tmpTbl]
END

推荐答案

Order By 放在 Select * From #tmpTbl 上,而不是放在 insert 上.

Put the Order By on the Select * From #tmpTbl, not on the insert.

这篇关于查询每次运行返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆