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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:35:45+00:00 2026-05-30T13:35:45+00:00

Running most recent version of PHP under most recent build of WAMPserver. Database is

  • 0

Running most recent version of PHP under most recent build of WAMPserver.

Database is SQL Server 2005

Here is the query I am currently running that works. What I want to do is change the output from:

CorrectionsCount , Employee  , Date    
1                , Joe       , 02/12/2012
31               , Barbara   , 02/13/2012    
12               , Paula     , 02/16/2012

To something like this

[EMPLOYEE NAME], 02/12/2012,    02/13/2012,    02/16/2012    
Joe              , 31         , 0              , 0    
Barbara          , 0          , 31             , 0   
Paula            , 0          , 0              , 12

Code:

<?php

// connect to DSN 
$DP2connect = odbc_connect("DB", "USER", "PWORD") or die ("Could not connect to 

server");

$DP2query = "
SELECT SUM(CorrectionsCount),CorrectionUser,
convert(char(10), DateHourCorrected, 120)
FROM ISIImageCorrections
WHERE DateHourCorrected BETWEEN '$theDate1' AND '$theDate2'
GROUP BY CorrectionsCount,CorrectionUser,DateHourCorrected
";


$DP2result2 = odbc_exec($DP2connect, $DP2query);

odbc_result_all($DP2result2, 'id="results"');
?>

$thedate1 and $thedate2 are variables being POSTed to this page by a calendar picker from another PHP page.

UPDATE: I tried running the COALESCE function described below, but it generates a syntax error near the keyword ‘FROM’ (the second instance of “FROM” in this statement). Am I inputting it properly?

$DP2connect = odbc_connect("dp2_database", "DP2", "DP2Express!") or die ("Could not connect to 

server");

$DP2query = 
"WITH T 
AS(
    SELECT CorrectionUser, CorrectionsCount, DateHourCorrected
    FROM ISIImageCorrections
)
SELECT CorrectionUser, 
       COALESCE([02/12/2012], 0) AS [02/12/2012],
       COALESCE([02/13/2012], 0) AS [02/13/2012],
       COALESCE([02/16/2012], 0) AS [02/16/2012],
FROM T
PIVOT(SUM(CorrectionsCount) FOR [Date] IN([02/12/2012], [02/13/2012], [02/16/2012])) AS P";


$DP2result2 = odbc_exec($DP2connect, $DP2query);

odbc_result_all($DP2result2, 'id="results"');
  • 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-30T13:35:46+00:00Added an answer on May 30, 2026 at 1:35 pm

    Here I am using SUM, choose any aggregate function of your liking:

    WITH T AS(
        SELECT Employee, CorrectionsCount, [Date]
        FROM @yourTable
    )
    SELECT Employee, 
           COALESCE([02/12/2012], 0) AS [02/12/2012],
           COALESCE([02/13/2012], 0) AS [02/13/2012],
           COALESCE([02/16/2012], 0) AS [02/16/2012]
    FROM T
    PIVOT(SUM(CorrectionsCount) FOR [Date] 
          IN([02/12/2012], [02/13/2012], [02/16/2012])) AS P;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I am not running the most up-to-date version of ACT on my
When running PHP in CLI mode, most of the time (not always), the script
I am running my application under a profiler. The 'class' that has the most
How do most people handle updating ASP.NET applications running in a webfarm? I am
My application is running on Google App Engine and most of requests constantly gets
I'm trying to figure out the most efficient way to running a pretty hefty
I'm running a site that allows users to make comments, and most of them
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
im running python 3.1.2 on my ubuntu 10.04 which version of BeautifulSoup i need
I am trying to get the 64-bit version of python up and running with

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.