Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can anyone reCODE this??
Message
 
 
To
29/11/2005 21:44:58
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01073083
Message ID:
01073092
Views:
16
>Hi to all,
>
>Is there any other of doing this?
>
<snip>

It's not a good idea to use meaningless one letter table aliases. They make queries unreadable and hard to maintain. Also, there's ISNULL() function to deal with NULLs. Finally, try
SELECT cr.COURSE_CODE, cr.SCHOOL_KEY,
		ISNULL( SUM( CASE WHEN pc.STUD_YEAR = 1 
					THEN pc.BALANCE + pc.PRELIM_PAYMENT ELSE 0 END ), 0 ) * .40 AS FIRST_YEAR,
		ISNULL( SUM( CASE WHEN pc.STUD_YEAR = 2 
					THEN pc.BALANCE + pc.PRELIM_PAYMENT ELSE 0 END ), 0 ) * .40 AS Second_YEAR,
...
		ISNULL( SUM( CASE WHEN pc.STUD_YEAR = 5 
					THEN pc.BALANCE + pc.PRELIM_PAYMENT ELSE 0 END ), 0 ) * .40 AS Fifth_YEAR
	FROM Courses cr
		JOIN VW_PRELIM_COLLECTIBLES_YEAR pc 
			ON cr.Course_Code = pc.Course_Code
	WHERE     (pc.SCHOOL_KEY <> 4)
	GROUP BY pc.COURSE_CODE, pc.SCHOOL_KEY
	ORDER BY pc.SCHOOL_KEY
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform