Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 23rd, 2017, 05:33 AM
Registered User
 
Join Date: Dec 2017
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Translate to MySQL ?

I tried this translation of your pseudocode but it returns NULL when there is actually data. Anything wrong with my syntax or logic?

SELECT LastTeachingOrg, YEAR(Date),

SUM(CASE WHEN MONTH(Date) = 01 THEN Income ELSE 0 END) AS Jan, SUM(CASE WHEN MONTH(Date) = 02 THEN Income ELSE 0 END) AS Feb, SUM(CASE WHEN MONTH(Date) = 03 THEN Income ELSE 0 END) AS Mar, SUM(CASE WHEN MONTH(Date) = 04 THEN Income ELSE 0 END) AS Apr, SUM(CASE WHEN MONTH(Date) = 05 THEN Income ELSE 0 END) AS May, SUM(CASE WHEN MONTH(Date) = 06 THEN Income ELSE 0 END) AS Jun, SUM(CASE WHEN MONTH(Date) = 07 THEN Income ELSE 0 END) AS Jul, SUM(CASE WHEN MONTH(Date) = 08 THEN Income ELSE 0 END) AS Aug, SUM(CASE WHEN MONTH(Date) = 09 THEN Income ELSE 0 END) AS Sep, SUM(CASE WHEN MONTH(Date) = 10 THEN Income ELSE 0 END) AS Oct, SUM(CASE WHEN MONTH(Date) = 11 THEN Income ELSE 0 END) AS Nov, SUM(CASE WHEN MONTH(Date) = 12 THEN Income ELSE 0 END) AS Dec,
COUNT(*) AS Total

FROM

SELECT LastTeachingOrg, YEAR(Date), MONTH(Date), Income FROM salarydb
WHERE (`salarydb`.`Username` = `kp`)

GROUP BY LastTeachingOrg, YEAR(Date), MONTH(Date) ) salarydb
WHERE (`salarydb`.`Username` = `kp`)

GROUP BY salarydb.LastTeachingOrg, YEAR(Date)

WITH ROLLUP

ORDER BY salarydb.LastTeachingOrg, YEAR(Date);





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting month name to month number kalyanykk SQL Server 2005 7 August 19th, 2008 10:37 PM
Sql Query to generate months and year arul1984 SQL Server 2000 8 July 23rd, 2007 04:42 PM
query Current Month, Month+1, Month+2, Month+3 anterior Access 2 September 24th, 2006 08:25 PM
Query birthdate by month Batusai Access 2 February 23rd, 2005 01:23 AM
efficiency qn xml vs sql server - to record counts ak Classic ASP Databases 3 March 3rd, 2004 05:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.