June 23, 2003 at 3:33 pm
It's been a long day, and I'm drawing a blank on how to get the data I'm after.
I've got a table that has a column called "countedby", and it has the business rule on how the data was collected; unfortunately it's sometimes a null value.
I'm trying to pull together both the nulls and the 1's as the assumed value;
here's an example:
--DATA
CREATE TABLE #FRUIT (COUNTEDBY INT,APPLES INT,ORANGES INT)
INSERT INTO #FRUIT VALUES (NULL,4,7)
INSERT INTO #FRUIT VALUES (NULL,5,7)
INSERT INTO #FRUIT VALUES (1,NULL,3)
INSERT INTO #FRUIT VALUES (2,4,NULL)
INSERT INTO #FRUIT VALUES (1,6,7)
INSERT INTO #FRUIT VALUES (2,7,5)
SELECT
ISNULL(COUNTEDBY,1) AS COUNTEDBY,
SUM(ISNULL(APPLES,0)),
SUM(ISNULL(ORANGES,0))
FROM #FRUIT
GROUP BY COUNTEDBY
DROP TABLE #FRUIT
The data returned is similar to this:
COUNTEDBY
----------- ----------- -----------
1 9 14
1 6 10
2 11 5
In this case, I don't want a row for the Null values, I wanted them to be merged into the values that had the value of 1.
Could someone point out what I'm missing to get this to merge the nulls and the 1's together?
Lowell
June 23, 2003 at 3:50 pm
How about :
SELECT
isNull(COUNTEDBY,1) as Countedby,
SUM(ISNULL(APPLES,0)),
SUM(ISNULL(ORANGES,0))
FROM #FRUIT
GROUP BY isNull(COUNTEDBY,1)
this seems to be giving the results that you are looking for...I think....
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply