I need to export my query results from SQL Server 2008 to a CSV file and I wanted to know what is the easiest/best way to add a ID KEY (basicly a row number field) to my CSV file. Should I do this in the query? If so what would be the best code to do this? Or is there a way to add this type of “row number” field when exporting as CSV from SQL Server 2008?
Share
The easyest way is to use Excel or other spreedsheet editor to generate this numbers for you.
Just type in the first and second number and doubleclick on the black square at the bottom right corner of the seconde cell and you’re good to go.
To make it with SQL you can use
ROW_NUMBER() OVER(ORDER BY some fields asc, ...)http://msdn.microsoft.com/pt-br/library/ms186734.aspx