|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
I have to change column position with sql or tsql.
I have a table with 3 column: column 1, column 2, column 3. I want to move for example column 2 before column 1 or after column 3. Can anyone help me? tks a lot |
|
#2
|
|||
|
|||
|
Why? The physical order is irrelevant.
Code:
select column3,column1,column2 from t |
|
#3
|
|||
|
|||
|
This table is created dinamically by the user. Then I have to retrieve name of column and values and I do it with a For...Next cycle. So it display the field one by one order by their phisical order.
The admin need to modify in a second moment which is the correct order to display the fields so I have to change the position of the column in the table. |
|
#4
|
||||
|
||||
|
Or create a view ...
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#5
|
|||
|
|||
|
Re
In my application the admin create the table (with the fields he wanted) and the user insert the data into the table. But the admin need to change the position of the fields.
My problem is not the way to display data but the way to display the name of the field. |
|
#6
|
|||
|
|||
|
Ya know I don't know an easy way to do it, but I can't help but think the order of which the field data is entered in the front end and the "order" of the fields in the table is of no matter. You can't dump the values the Admin enters into variables, then in your INSERT dump the variables (in desired order) into the table?...@least that's how I handled a similar situation w/a recent Java app.
If you must though, the only thing I could think to do is create a view of the table (select the fields in the desired order), insert that view into a temp table, wipe out the old table and lay it back out again in the desired order...insert values from the temp table. Sorry, my SQL is limited, but that's all I could think of. Last edited by Username=NULL : April 26th, 2004 at 06:49 AM. |
|
#7
|
||||
|
||||
|
null, good one
i would skip the view and just define the temp table ![]() kenda, if you need to, you can get the names of the fields from the INFORMATION_SCHEMA tables -- check Books OnLine however, i don't think you need to just rename your table, then define a view on it using the original name everything should keep running exactly as before, the columns will just appear to be in a different order Last edited by r937 : April 26th, 2004 at 10:01 AM. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > change column position |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|