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

  • SEARCH
  • Home
  • 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 3623842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:26:00+00:00 2026-05-18T23:26:00+00:00

my current query return the below result What I need is I have to

  • 0

my current query return the below result
alt text

What I need is I have to display date in column header. I know it have to be done using Pivot

Example: if we want to display month in column header then query will be something like..

SELECT  [January], [February], [March]
FROM    ( SELECT    [Month], SaleAmount
          FROM      Sales
        ) p PIVOT ( SUM(SaleAmount)
                    FOR [Month] 
                      IN ([January],[February],[March])
                  ) AS pvt

and I think my resultant query should be look like Pivot ( (Price) FOR [DateVal] IN (What will be here?) ) here is what resultant column should be like
alt text

Note: in the result set currently it show December month data, but it can be any month.

Thanks for your help…

  • 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-18T23:26:00+00:00Added an answer on May 18, 2026 at 11:26 pm

    Update 4
    Ok, now that you posted all your query, and following your comments, you should try this:

    DECLARE @FirstDay SMALLDATETIME
    SELECT @FirstDay = CONVERT(SMALLDATETIME, (@year + '-' + @month + '-01')); 
    
    WITH Dates AS  
    (
      SELECT @FirstDay AS DateVal 
      UNION ALL 
      SELECT DATEADD(d, 1, DateVal) AS DateVal 
      FROM Dates 
      WHERE DATEADD(d, 1, DateVal) < DATEADD(m, 1, @FirstDay)
    )
    
    SELECT * INTO #Dates FROM Dates
    
    DECLARE @hotelID INT, @packageID INT, @year VARCHAR(4), @Dates VARCHAR(1000), @month VARCHAR(2), @Query VARCHAR(MAX)
    SELECT @hotelID=248, @packageID=76, @year='2010', @month='12',@Dates=''
    
    SELECT co.*,wb.Name,rc.HotelName 
    INTO #HotelData
    FROM RCompetitorOccupancy co 
    INNER JOIN websites wb ON wb.websiteid=co.websiteid
    INNER JOIN RoomCompetitor rc ON rc.competitorid=co.competitorid
    WHERE YEAR(occDate)=@year AND MONTH(occdate)=@month AND packageid=@packageID 
    AND roomTypeid IN (SELECT roomtypeid FROM CompetitorRoomType WHERE DESCRIPTION=119)
    
    SELECT @Dates = @Dates + '[' + CAST(DATEPART(DAY,DateVal) AS VARCHAR(2)) + '-' + LEFT(DATENAME(MONTH,DateVal),3)+ '],'
    FROM #Dates
    GROUP BY Dateval
    
    SET @Dates = LEFT(@Dates,LEN(@Dates)-1)
    
    SET @Query = '
    SELECT roomtypeid, description, [Name], [HotelName], '+@Dates+'
    FROM (  SELECT  HD.roomtypeid, HD.description, HD.[Name], HD.[HotelName], HD.Price, 
                    CAST(DATEPART(DAY,DateVal) AS VARCHAR(2)) + ''-'' + LEFT(DATENAME(MONTH,DateVal),3) [Date]
            FROM #Dates D
            LEFT JOIN #HotelData HD
            ON D.DateVal = HD.OccDate) T
    PIVOT ( SUM(Price) FOR [Date] IN ('+@Dates+') ) AS PT'
    
    EXEC(@Query)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that generate the query result like below: channel | current_Month
I need to combine my main query with a subquery: Current query (which works):
My current LINQ query and example XML are below. What I'd like to do
If I have a query like this: String Category = HttpContext.Current.Request.QueryString[Product].ToString(); IQueryable<ItemFile> pressReleases =
I have a number of database tables below. I want to display each user
I want a query that will return a row for each column in a
Is it possible to do the below requirement in C# 4.0 Current: I have
I have the below SQL query: SELECT g.name AS gname, COUNT(u.id) AS noMembers, f.name
I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It
In my asp.net application, I have the below static class to handle query strings

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.