Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL View with ID column

Tags:

sql

view

I'm working with a SQL view that I created but I want to add in an ID column (identity seed) as the current one has none. How can I accomplish this in SQL View?

enter image description here

like image 250
GabrielVa Avatar asked Nov 09 '11 16:11

GabrielVa


1 Answers

If there is no identity column in the underlying table, you can generate one with pseudo-columns.

In SQL server: SELECT ROW_NUMBER() OVER (ORDER BY FiscalYear, FiscalMonth), FiscalYear, FiscalMonth, ... FROM ... See http://msdn.microsoft.com/en-us/library/ms186734.aspx

In Oracle: SELECT ROWNUM, FiscalYear, FiscalMonth, ... FROM ... . In oracle, ROWNUM uses the order in the result set.

like image 186
GeertPt Avatar answered Oct 11 '22 07:10

GeertPt