April 8, 2011 at 7:40 pm
I want to reorder my table by DteTme and save everything back into the same table which is Main_Table. Does anyone know what the SQL would be to do that?
April 8, 2011 at 7:47 pm
Read this article on SSC
Sorting Months By Number (SQL Spackle)
By Jeff Moden, 2010/11/15
Here is the link to the article:
April 8, 2011 at 8:19 pm
I'm reading it right now. It is a bit over my head though. I'm not quite that advanced yet. I see you can use ORDER BY but I don't really see how I can ORDER BY and stuff everything back into the same table.
April 8, 2011 at 9:22 pm
sql doesn't really need the data in a specific order; you should typically just use an order by when you need the data in a specific order.
it uses indexes to find the data.
technically the data in a table is stored in the same order as the clustered index of the table. so if you did a table with a typical "int identity(1,1) not null primary key", that column is the order the data is stored, because unless you tell it otherwise, SQL assumes the primary key is the best candidate for the clustered index when you build the table
so if you REALLY wanted to store the data in the order of your date column , you would want to drop the clustered index and create a new one.
Lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply