Sorting via script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kelly Mayo

    Sorting via script

    I have a movie db in sql 7 that I like to keep sorted by title. I have been
    exporting to another table, and sorting output by title, then deleting the
    original table and renaming the new table to the old tablename.

    I would love to script this but dont know how to rename a table. I can drop
    and create via script, but thats it. Any help appreciated...

    There is probably a better way to do this but I dont know it. Of course I
    could always sort during the query but I like to have it presorted.

    Thanks,

    Kelly


  • mountain man

    #2
    Re: Sorting via script

    "Kelly Mayo" <krmayo@yahoo.c om> wrote in message
    news:CERZb.5199 $hN6.2609@newss vr23.news.prodi gy.com...[color=blue]
    > I have a movie db in sql 7 that I like to keep sorted by title. I have[/color]
    been[color=blue]
    > exporting to another table, and sorting output by title, then deleting the
    > original table and renaming the new table to the old tablename.
    >
    > I would love to script this but dont know how to rename a table. I can[/color]
    drop[color=blue]
    > and create via script, but thats it. Any help appreciated...
    >
    > There is probably a better way to do this but I dont know it. Of course I
    > could always sort during the query but I like to have it presorted.[/color]


    Have a look at sp_rename (table).

    The sort order specified in a query script
    does actually work every time.







    Comment

    • John Bell

      #3
      Re: Sorting via script

      Hi

      I am slightly confused by this, as you seem to think that the data in the
      new table is sorted! The only way you can guarantee an order for data
      returned by a query is to specify an ORDER BY clause.
      What you may require is to reindex or defragment the indexes on your table,
      but this will not guarantee order.

      John

      "Kelly Mayo" <krmayo@yahoo.c om> wrote in message
      news:CERZb.5199 $hN6.2609@newss vr23.news.prodi gy.com...[color=blue]
      > I have a movie db in sql 7 that I like to keep sorted by title. I have[/color]
      been[color=blue]
      > exporting to another table, and sorting output by title, then deleting the
      > original table and renaming the new table to the old tablename.
      >
      > I would love to script this but dont know how to rename a table. I can[/color]
      drop[color=blue]
      > and create via script, but thats it. Any help appreciated...
      >
      > There is probably a better way to do this but I dont know it. Of course I
      > could always sort during the query but I like to have it presorted.
      >
      > Thanks,
      >
      > Kelly
      >
      >[/color]


      Comment

      • Dandy WEYN

        #4
        Re: Sorting via script

        exactly the only way to retrieve the data in the correct order is by using
        an order by clause, so you have no need on recreating the table and import
        them with an order by clause.


        --
        Dandy Weyn, Belgium
        MCSE, MCSA, MCDBA, MCT



        Check my SQL Server resource pages (currently under construction)



        "Kelly Mayo" <krmayo@yahoo.c om> wrote in message
        news:CERZb.5199 $hN6.2609@newss vr23.news.prodi gy.com...[color=blue]
        > I have a movie db in sql 7 that I like to keep sorted by title. I have[/color]
        been[color=blue]
        > exporting to another table, and sorting output by title, then deleting the
        > original table and renaming the new table to the old tablename.
        >
        > I would love to script this but dont know how to rename a table. I can[/color]
        drop[color=blue]
        > and create via script, but thats it. Any help appreciated...
        >
        > There is probably a better way to do this but I dont know it. Of course I
        > could always sort during the query but I like to have it presorted.
        >
        > Thanks,
        >
        > Kelly
        >
        >[/color]


        Comment

        Working...