Is there any way to get the first and last records date in SQL Server like if I have a table with single column and no date column.
Asked
Active
Viewed 77 times
0
-
According to http://stackoverflow.com/questions/10834610/date-of-inserting-a-row-into-table it is not possible to find this out without a Date/Time column on the table – developer__c Jan 06 '15 at 13:29
-
1The best way is to add a datetime column. – Tim Schmelter Jan 06 '15 at 13:31
-
Just add a new column to your table called datetime and then populate it automatically, you could do this by having the default as NOW() – developer__c Jan 06 '15 at 13:34
-
2By SQL definitions, tables are an *unordered* bag of rows. The only time it makes sense to talk using positional terms such as first or last is if you've *defined* an order based on one or more of the columns (which usually means you'll need to have those columns in the `ORDER BY` clause of the query in which you're using those positional terms) – Damien_The_Unbeliever Jan 06 '15 at 13:39
-
if you have a unique key on the table you might be able to make use of the %%physloc%% to determine this without having a date column, this answer has more information http://stackoverflow.com/questions/909155/equivalent-of-oracles-rowid-in-sql-server – Richard Hansell Jan 06 '15 at 14:14