Sort Columns

  • I have come up with a query with lot of columns to be used in a report.

    I named the column such that all with QA... , Dat.... but they all show random.

    Is there a way to see them in a particular order .

  • Can you show an example of what you mean? Without seeing code, it's hard to understand what you mean.

  • sharonsql2013 (8/25/2015)


    I have come up with a query with lot of columns to be used in a report.

    I named the column such that all with QA... , Dat.... but they all show random.

    Is there a way to see them in a particular order .

    If I have several columns that I would like to sort I get a list of the columns (sys.all_columns) and take it to Excel to sort then take the result back to SSMS.

    Are you using the results of a query directly for the report or are you using a reporting tool?

  • We can sort data returned by a query in SQL Server using Order By clause:

    •Order the result set of a query by the specified column list and, optionally, limit the rows returned to a specified range. The order in which rows are returned in a result set are not guaranteed unless an ORDER BY clause is specified.

    •Determine the order in which ranking function values are applied to the result set.

    Reference:

    ORDER BY Clause (Transact-SQL)

    SQL: ORDER BY Clause

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

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