Resorting a Database View by Alias

  • Fairly new to SQL server and while I'm pretty familiar with it, I have a ways to go yet. My problem is this:

    Using SQL Server 2000, I've used Enterprise Manager to create a view that uses an INNER JOIN to join about 6 tables together. When you check the fields to include in the table view, it adds them to the SQL Select statement in the order that you selected them. I've since gone in and added Aliases to each of these fields to make them easier for the end user to understand, but would like to be able to re-sort the order that the view displays the fields, so that there is some logic to it rather than just the order I picked them in the tables. I'd like to go alphabetically by the alias, so it makes it fairly easy to find the field you are looking for. Any help would be appreciated. Please let me know if you need clarification or have any questions about what I'm trying to do.

    - Josh

  • Copy ther select statment generated by Enterprise Manger in to Query analyser and adjust the select statement to suit your needs and past it back to the view.

    Hope that answers your question.

    Thanks

    Sreejith

  • I had already thought of that... problem being I have a large number of fields (in the vicinity of 250) and that would take a little less time than unchecking and rechecking all the fields.

  • Sounds a little whacked but with 250 columns, might not be as whacked as you think... copy the columns in the SELECT list to a text file (copy and paste them into any text editor).  Import the file into EXCEL using space as the delimiter.  Sort the resulting spreadsheet by the alias column.  Copy and paste from EXCEL back to the SELECT list.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I actually thought about doing this but the only issue is that my Aliases have spaces, so they are getting split up, which washes out any time I may have saved in Excel. Now I can use [ as the delimiter, but then I'm going in and readding it... unless.... oh I just had a stroke of Genius. I'll let you know how it works out

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply