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 8062385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:39:09+00:00 2026-06-05T10:39:09+00:00

I have a table variable with the datatype Varchar(MAX). I am inserting the value

  • 0

I have a table variable with the datatype Varchar(MAX).

I am inserting the value ‘header’ first, Then based on an inner join, I am next inserting ‘Details’ into the same table variable. Finally, I am inserting ‘Trailer’.

The output which I am getting is in the order: ‘header’, then ‘trailer’, and finally ‘details’.

My required output is in this order:

Header 
Detail
Trailer

But I am getting this order:

Header
Trailer
Detail

Note: I am not able to use asc/desc in the selection. I am inserting in the order I need.

  • 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-05T10:39:10+00:00Added an answer on June 5, 2026 at 10:39 am

    A SQL Database does not actually understand what order you put things in, or store the data in a given order. You probably want a second column in your table with a value to use so that whatever order you need is preserved.

    Think about it like handing some stuff to your friend to hold – she will have all of it for you later, but she stores it someplace in the mean time. She may move it around while you are not looking to make room for something else, or may hand it back in the same order you gave it to her, but you didn’t tell her to keep it in order, so she doesn’t.

    Databases need to be able to move things around in the background, so the way they are built does not intrinsically know about any order – you need to know the order when you give it to the database, so that you can put it back in the order you want later. The order clause allows SQL to impose an order on the data, but it doesn’t remember or have one on its own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table (table variable in-fact) that holds several thousand (50k approx) rows
I have the following table variable in SQL Server 2005: DECLARE @results TABLE (id
I have a single row in a table variable that looks like this: CanEdit
I have a classified_id variable which matches one document in a MySql table. I
Environment: SQL Server 2005/2008, pubs database I have inserted into a table variable a
I have a transaction table which has start_date and end_date of datetime datatype. I
I have a database table with a decimal(25) datatype. The data from this column
I have 2 table variable @Data and @DateTable @Data conatains the following: Company Date
I have a table variable that holds orderID , UnitID and OrderServiceId (it is
in my stored procedure I have a table variable contains rows ID. The are

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.