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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:56:45+00:00 2026-06-11T09:56:45+00:00

I have a query with PIVOT table, like, SELECT * FROM (SELECT ID, ID,Date

  • 0

I have a query with PIVOT table, like,

SELECT * 
   FROM (SELECT ID, ID,Date FROM Table1) AS P 
PIVOT 
    (   
      COUNT (P.ID)
      FOR P.Date in ([08/17/2006],[08/18/2006])  -- [MM/DD/YYYY] - Format
    ) as pvt

In above query, P.Date is datetime2(7) so, I am getting the data like,

P.Date = '2006-08-17 15:30:23.0000000' 

But i am comparing with '2006-08-17'. Here date part is same, even though I am not getting the results.

My aim is to display the count of the ID when the date matches.

I have tried with Convert(), But it is not allowing at PIVOT table in FOR block.

  • 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-11T09:56:46+00:00Added an answer on June 11, 2026 at 9:56 am

    You need to do the CAST() in the inner select:

    SELECT *
    FROM 
    (
      SELECT ID, ID, Cast(yourDateValue as Date) newdate  -- perform the conversion here
      FROM Table1 
    ) AS P 
    PIVOT 
    (   
      COUNT (P.ID)
      FOR newdate in ([08/17/2006], [08/18/2006])  -- [MM/DD/YYYY] - Format
    ) as pvt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have query to show the table like this: but I want to PIVOT
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have a query that looks like this: SELECT OrganizationName, OrganizationID, ReceivableStatus, InvoiceFee FROM
I have a query that successfully grabs the unique products from my products table
-- Pivot table with one row and four columns SELECT 'Values' tValues, ID,Name,ValueID,Value FROM
I have as a result from a dynamic query a table with only one
Using the MySQL query below, I have created a pivot table which is pretty
I have a simple query like this.. USE AdventureWorks; GO SELECT DaysToManufacture, AVG(StandardCost) AS
Possible Duplicate: SQL Server dynamic PIVOT query? I have temporary table with following structure:

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.