7

In SQL Server Management Studio (SSMS) running against SQL Server 2005, I have a solution which contains a number of views.

These views are not sorted alphabetically.

Can anyone provide either an explanation of why, or a solution to order them alphabetically ?

10 Answers 10

8

I just came across this forum post. It doesn't get any simpler.

Just edit the ssmssqlproj file.

The file for my project (SQL Main) is located in "My Documents\SQL Server Management Studio\Projects\SQL Main\SQL Main\SQL Main.ssmssqlproj". Its just an xml file. Change the following line

<LogicalFolder Name="Queries" Type="0" Sorted="true">

to

<LogicalFolder Name="Queries" Type="0" Sorted="false">

It will revert back to true so you need to repeat this if you make changes. THere is probably a better way Smile

3
  • fwiw, the bug where the Sorted attribute is ignored seems to have reappeared in 2008 as setting it either way does nothing. manually editing the project file or using an sproc like the one referenced by @Jacob Sebastian is the only way i've had any luck
    – kman
    Apr 25, 2013 at 14:17
  • I know this is an old post, but in response to the "2008 bug": I just tried this in MSSQL 2008 R2 and changing it to "false" appears to have corrected the sort order. Previously, it was not sorted alphabetically. As soon as I made the change and relaunched, it was sorted alphabetically.
    – Aron
    Jun 7, 2016 at 13:33
  • 1
    Works on SSMS 2016 too!
    – John Alan
    Jan 4, 2017 at 11:04
3

There is a tool that you can install to sort the contents of a SQL Server Solution project.

See the following reference.

http://web.archive.org/web/20121019155526/http://www.sqldbatips.com/showarticle.asp?ID=78

Please ensure you save your work, before attempting a sort.

2

When you add new item to the project they are added to the end of the list. They are kept in the order that they were added to the project because this order is preserved in the corresponding *.ssmssqlproj file. To change this order, close the project/solution, then locate the *.ssmssqlproj file and edit it with Notepad or your favorite XML editor (always make a backup first!). Reorder the FileNode elements along with their children to reorder the items appearance in the Solution Explorer.

2

Here's the solution I took. Up votes for the recommendation of the source code, however I don't have .NET installed here, so I had to go for a manual approach.

  1. finish working on any project or solution files you have checked out, and check these edits in.
  2. get latest version on everything in the solution.
  3. Check everything out
  4. Backup the whole folder structure
  5. open the .ssmssqlproj file in notepad
  6. maximise notepad full screen and turn word-wrapping off
  7. edit the .ssmssqlproj file, reordering the XML nodes in the required order
  8. save the .ssmssqlproj file
  9. check everything back in.

That seems to have fixed my issue.

2

The stored procedure listed in the following post can do it as well: http://beyondrelational.com/blogs/jacob/archive/2009/08/22/xquery-lab-48-sorting-query-files-in-sql-server-management-studio-ssms-solution-project.aspx

2

Please note that the sorting is case-sensitive.

So "B..sql" will come before "a...sql".

Remember to start all your scripts with the same casing (be it lower or upper).

0

Another easier (I think) way to edit the ssmssqlprog is to do so with MS XML Notepad 2007. With that I could drag the nodes around to order them. Make a copy of course. 2007 appears to be the latest version and is available at ...

http://www.microsoft.com/en-us/download/details.aspx?id=7973

0

Another way to handle this is to start with a new query from Management Studio (not by selecting 'New Query' in the solution).

Save the query file into the solution folder with a good name. Then 'Add Existing Item' into the solution.

It adds with your chosen name, sorted correctly instead of creating the file initially as 'SQLQuery1'.

Maybe not much better, but another option to editing the project file and reopening.

0

Building on the previous answer, you can add it as a new query in the solution, and when you are done, just remove it from the solution and then Add existing item to the solution, and select your new query. Doing it this way adds the new query to the correct solution folder for you before you remove and add back in.

0

And yet another way... while one of these ways worked for me several times... sometimes it becomes stubborn. Find the location where it is broken. Take a screenshot of the file names. Select all the file names you need to remove before the glitch. in other works, if it sorts a - f and then sorts b - z Remove all the a-f (don't delete them) that occur before the b-z, then save the project. Now add them back in and save the project again. Presto. So far this has worked very well for me and is fairly easy to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.