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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:16:24+00:00 2026-05-16T12:16:24+00:00

I have a table var with some rows but only one column of type

  • 0

I have a table var with some rows but only one column of type DATETIME, like this:

[Day]
2010-08-03
2010-08-04
2010-08-10
2010-08-11

I need to show on some columns but in only one row.
My result set will be limited to 5 rows, then I can limit to 5 columns too.
Example of what I need:

[Day1]      [Day2]      [Day3]      [Day4]      [Day5]
2010-08-03  2010-08-04  2010-08-10  2010-08-11  NULL

I was trying to do it using PIVOT in SQL Server 2005.
But all examples uses more columns to agregate values, then I’m not understanding.

This is the query I was trying:

SELECT r.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY Day ASC) Line, Day FROM @MyDays) AS o
PIVOT (MIN(Line) FOR Day IN (Day1, Day2, Day3, Day4, Day5)) AS r

But the result is all NULL:

[Day1]  [Day2]  [Day3]  [Day4]  [Day5]
NULL    NULL    NULL    NULL    NULL

Could someone show me what I’m doing wrong?

  • 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-05-16T12:16:24+00:00Added an answer on May 16, 2026 at 12:16 pm

    Row_Number() just returns a number in the list 1-5 so it isn’t going to match anything in your list “Day1, Day2, Day3, Day4, Day5”. I have appended “Day” onto the front so it will.

    Additionally you have MIN(Line) FOR Day IN, This needs to be the otherway around. It is the value of Day that you are wanting to display.

    ;with mydays as
    (
    
    SELECT '2010-08-03' AS [Day] UNION
    SELECT '2010-08-04' AS [Day] UNION
    SELECT '2010-08-10' AS [Day] UNION
    SELECT '2010-08-11' AS [Day] 
    )
    SELECT r.* FROM (
       SELECT 
          'Day' + CAST( ROW_NUMBER() OVER (ORDER BY Day ASC)as varchar(10)) Line, 
           Day 
       FROM mydays) AS o
    PIVOT (MIN([Day]) FOR Line IN (Day1, Day2, Day3, Day4, Day5)) AS r
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a table where all rows have at least one class. Some
I have a script that appends some rows to a table. One of the
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a table with more than a millon rows. This table is used
I have a table which is full of arbitrarily formatted phone numbers, like this
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have a table with a structure like the following: LocationID AccountNumber long-guid-here 12345
So I have this (huge) table , classed with css (big_conv_tbl) . All empty

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.