Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8904959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:16:08+00:00 2026-06-15T02:16:08+00:00

Given: You can sort result set by indicating index of column. SELECT * FROM

  • 0

Given:

You can sort result set by indicating index of column.

SELECT * FROM CUSTOMERS ORDERY BY 1

I’m trying to use in the following context, however, I get error message:

Msg 5308, Level 16, State 1, Line 8
Windowed functions do not support integer indices as ORDER BY clause expressions.

EXEC ("
SELECT  *, 
        ROW_NUMBER() OVER ( ORDER BY 1 ) AS 'Seq'   
from dynamic_table");

Can you think of a work-around?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:16:09+00:00Added an answer on June 15, 2026 at 2:16 am

    If you know the column name this should work:

    Exec ("
    select *, 
    ROW_NUMBER() OVER ( ORDER BY " + columnName + " ) AS 'Seq'   
    from dynamic_table");
    

    If the column name is not known:

    DECLARE @table_name nvarchar(100) = 'test'
    DECLARE @column_name nvarchar(100) 
    SELECT 
        @column_name = columns.name
    FROM sys.columns
    inner join sys.tables ON tables.object_id = columns.object_id
    WHERE tables.name = @table_name and column_id = 1
    
    EXEC ('
    select *, 
    ROW_NUMBER() OVER ( ORDER BY ' + @column_name + ' ) AS ''Seq''   
    from ' + @table_name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can you sort the following word by the given rule? Example data is
I'm wondering if the index of an array can be given a name in
Given an Youtube video id how can I determine from JavaScript whether the video
So I'm trying to make a Python app that's sort of like a set
I want to sort my sphinx result with document id. By any change can
I'm hoping someone has run into this sort of problem before, and can give
Given doubles can't be used in volatile fields, is this a safe alternative? Or
Given a date how can I add a number of days to it, but
Given virtual directory and port can you find the actual path of a web
How can i filter the link given in link to existing content. As in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.