Sql server 2005 无法从SQL Server查询中获得正确的输出
这是我的存储过程。在这里,我想从500行,但我从250行数。。。。任何人都知道它为什么会发生……谢谢用作Sql server 2005 无法从SQL Server查询中获得正确的输出,sql-server-2005,Sql Server 2005,这是我的存储过程。在这里,我想从500行,但我从250行数。。。。任何人都知道它为什么会发生……谢谢用作不在的数据源的子查询没有ORDER BY子句。因此,查询引擎可以按照它认为合适的顺序自由选择TOP(@end)行。我希望您希望跳过TOP@end注册,按注册ID排序 您应该尝试下面的代码 ALTER PROCEDURE [dbo].[Sp_GetEmailForMailing] -- Add the parameters for the stored procedure here
不在
的数据源的子查询没有ORDER BY
子句。因此,查询引擎可以按照它认为合适的顺序自由选择TOP(@end)
行。我希望您希望跳过TOP@end注册,按注册ID排序
您应该尝试下面的代码
ALTER PROCEDURE [dbo].[Sp_GetEmailForMailing]
-- Add the parameters for the stored procedure here
@end int=1000
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT top(500) RegistrationID, EmailID from dbo.Candidate_RegistrationData
where status_flag=1 and payment_status=2
and RegistrationID NOT IN (SELECT top(@end) RegistrationID from dbo.Candidate_RegistrationData
where status_flag=1 and payment_status=2) order by RegistrationID
END
你的意思是,第一次@end注册将被跳过?按注册ID升序?
ALTER PROCEDURE [dbo].[Sp_GetEmailForMailing]
@end int = 1000
AS
SET NOCOUNT ON;
BEGIN
Select Top(500) RegistrationID, EmailID From
(
Select Row_Number() Over(Order by RegistrationID) as RowId,
RegistrationID,
EmailID,
status_flag,
payment_status
From dbo.Candidate_RegistrationData
Where status_flag = 1 and payment_status = 2
)T
Where RowId > @end and status_flag = 1 and payment_status = 2
Order By RegistrationID
End