In order to generate a sequential number in SQL Server, you can use the keyword 'ROW_NUMBER' in its correct format as follows:
As an example how to generate a sequential number in SQL Server, look at the following example:
SELECT ROW_NUMBER() OVER(PARTITION BY ColumnName ORDER BY AnotherColumnName) AS ColumnAlias
References:
- type in the keyword 'NOW_NUMBER'
- follow it by the keyword 'OVER', it takes two parameter:
- The first one is to indicate the column in which you want to reset the sequential number based on
- The second is the order of that data in which the sequential number come along with.
- Note: The fist parameter is optionally whereas the second is manadatory.
- give an alias for the column using the keyword 'AS'
As an example how to generate a sequential number in SQL Server, look at the following example:
SELECT ROW_NUMBER() OVER(PARTITION BY ColumnName ORDER BY AnotherColumnName) AS ColumnAlias
References:
- http://msdn.microsoft.com/en-us/library/ms186734.aspx
- Training Kit (Exam 70-461) Querying Microsoft SQL Server 2012
No comments:
Post a Comment