0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ankush sharma
  • 83
  • 1
  • 5
  • 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
  • 1
    The 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
  • 2
    By 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

0 Answers0