Saturday, March 29, 2008

Add Serial Number to Our Query Result

Sometimes, we need to add serial number in our query result to show on the report. I’m not sure SQL 2000 has this feature or not but I never use that feature in SQL 2000. :D In SQL 2005, we’ve one function call ROW_NUMBER(). So we can display serial number in our query result. The example for that function is as follow:

SELECT ROW_NUMBER() OVER(ORDER BY customername) FROM customer WHERE customername LIKE ‘John%’

You can see detail description of this function at Microsoft MSDN Online
.

1 comment:

exotic.ankit said...

hey! thanks a lot... this worked for me. You really made it worked.
God Bless you