Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old December 23rd, 2017, 05:33 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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);
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.