prodigymunky
04-10-2006, 10:41 AM
Here's the SQL command I'm trying to impliment ...
SELECT DISTINCT
t.ID AS ID,
t.topTitle AS topTitle,
t.topDescription AS topDescription,
t.topCategory AS topCategory,
t.topOrder AS topOrder,
(SELECT
COUNT(posTopic)
FROM posts
WHERE posTopic = t.ID
AND posParent = 0
)
AS topPosts,
(SELECT
COUNT(posTopic)
FROM posts
WHERE posTopic = t.ID
AND posParent <> 0
)
AS topReplies,
(SELECT
MAX(posTimestamp)
FROM posts
WHERE posTopic = t.ID
)
AS topRecentTimestamp,
( CASE WHEN ( SELECT MAX(posTimestamp) FROM posts WHERE posTopic = t.ID )
IS NULL THEN 0
ELSE ( ( SELECT posAuthor FROM posts WHERE posTopic = t.ID AND posTimestamp = ( SELECT MAX(posTimestamp) FROM posts WHERE posTopic = t.ID ) ) )
END )
AS topRecentAuthor
FROM
topics t,
posts p
WHERE
t.topCategory = 1
ORDER BY
t.topOrder
Everything works fine except for the CASE command. The individual SELECT commands inside the CASE command work fine, but when I put them all together into the CASE command, it fails. Does anyone know why?
SELECT DISTINCT
t.ID AS ID,
t.topTitle AS topTitle,
t.topDescription AS topDescription,
t.topCategory AS topCategory,
t.topOrder AS topOrder,
(SELECT
COUNT(posTopic)
FROM posts
WHERE posTopic = t.ID
AND posParent = 0
)
AS topPosts,
(SELECT
COUNT(posTopic)
FROM posts
WHERE posTopic = t.ID
AND posParent <> 0
)
AS topReplies,
(SELECT
MAX(posTimestamp)
FROM posts
WHERE posTopic = t.ID
)
AS topRecentTimestamp,
( CASE WHEN ( SELECT MAX(posTimestamp) FROM posts WHERE posTopic = t.ID )
IS NULL THEN 0
ELSE ( ( SELECT posAuthor FROM posts WHERE posTopic = t.ID AND posTimestamp = ( SELECT MAX(posTimestamp) FROM posts WHERE posTopic = t.ID ) ) )
END )
AS topRecentAuthor
FROM
topics t,
posts p
WHERE
t.topCategory = 1
ORDER BY
t.topOrder
Everything works fine except for the CASE command. The individual SELECT commands inside the CASE command work fine, but when I put them all together into the CASE command, it fails. Does anyone know why?