Table T1
---------------
Name Income
---------------
James 44000
Frank 140000
Robert 60000
---------------
I wish to have another table, which looks like
Table T2
---------------
Name Income
---------------
James 44000
Robert 60000
Frank 140000
---------------
Of course I can use a query that has the wanted order.
--------------------
Expand|Select|Wrap|Line Numbers
- SELECT Name, Income FROM T1 ORDER BY Income
However, I have to bcp out this query to disk and bcp it into Table T2. I think this might be low efficiency.
I can also use a cursor type of T-SQL (the T-SQL is just to show a concept and may not be working)
--------------------------------------
Expand|Select|Wrap|Line Numbers
- WHILE(SELECT COUNT(*) FROM T1 > 0)
- BEGIN
- INSERT INTO T2 (NAME, INCOME)SELECT NAME, MIN(INCOME)FROM T1
- DELETE FROM T1 WHERE INCOME = (SELECT MIN(INCOME) FROM T1)
- END
Is there a better way to do this?
Thanks