1
(SELECT 
    (SELECT ROW_NUMBER() OVER (order by t.NotificationID)) as  RowNumber,
            [NotificationID],[ProjectID],[TeamMemberID],[OperationType],
            [Hours],[Occurance],[Period],[NotificationText],
            [NotificationRecipientIDs],[NotificationRecipientClienitsIDs]

       FROM tblIA_Notifications t
       WHERE IsDeleted = 0 AND IsActive = 1
    ) 

上面的查询总是为每一行返回第 1 行。当我在外面使用 select 语句时,它的问题。否则,如果我删除外部选择语句就可以了。

我不明白这种行为。

4

2 回答 2

4

您正在为每一行获得 row_number 1,因为您正在为每一行选择 Row_Number
试试这个--->

SELECT        ROW_NUMBER() OVER (order by t.NotificationID) as RowNumber,
              [NotificationID],
              [ProjectID],
              [TeamMemberID],
              [OperationType],
              [Hours],
              [Occurance],
              [Period],
              [NotificationText],
              [NotificationRecipientIDs],
              [NotificationRecipientClienitsIDs]
    FROM      tblIA_Notifications    t 
    WHERE     IsDeleted    =    0 
    AND       IsActive = 1
于 2013-07-03T12:24:47.890 回答
2

尝试这个...

SELECT ROW_NUMBER() OVER (order by T.COLUMN_NAME) as RowNumber FROM [dbo].[TABLE_NAME] T
于 2013-07-17T09:35:33.017 回答