November 20, 2009 at 10:47 am
I have an interesting one..
is there a way to suppress the expressions from displaying in a select statement that at the end calculates the total sum...
Just want to see the sum / total nothing else..
here it is..
I have
select ..., foobar
from foobarVilleTable
compute sum(foobar)
You may be asking why? I am glad that you asked.. the list is in millions and kind of trying to avoid the verbowse part of that..
😀
Cheers,
John Esraelo
November 20, 2009 at 11:57 am
Is this what you are looking for?
SELECT entry AS ' ', SUM(Entryid) AS ' ' FROM foobarVille GROUP BY entry
November 20, 2009 at 12:10 pm
I have
select
200-len(tmessage) wastedspace
from mytable
compute sum(200-len(tmessage))
I hope this is clear..
thx
Cheers,
John Esraelo
November 20, 2009 at 3:32 pm
Is this what you mean?
CREATE TABLE #T(tmessage VARCHAR(200))
INSERT INTO #T
SELECT 'Short' UNION ALL
SELECT 'Longer' UNION ALL
SELECT 'Even a longer message' UNION ALL
SELECT 'A realy realy realy extra long message'
select SUM(200 -Len(tmessage)) AS WASTED,AVG(200 -Len(tmessage)) AS 'Average Wasted'
FROM #T
DROP TABLE #T
The results:
WASTEDAverage Wasted
730 . . . . . 182
If not then please refer to the link in my signature block and post the table definition, some sample data, so that those who want to help you can help you .
November 20, 2009 at 3:49 pm
thank you for the reply.
yes, this absolutely works great.
I was just wondering about the COMPUTE method and if there was a way not to show the PART ONE of the TWO of which the first section shows the detail of the records and the section two as you know then will show the total.
but, I believe I will use this method of course.
thx a lot
ciao
Cheers,
John Esraelo
November 20, 2009 at 4:01 pm
Now I do not really know why you are doing these calculations, but you could add one more item to the code to give you an overall view of the length of the contents of that table column:
CREATE TABLE #T(tmessage VARCHAR(200))
INSERT INTO #T
SELECT 'Short' UNION ALL
SELECT 'Longer' UNION ALL
SELECT 'Even a longer message' UNION ALL
SELECT 'A realy realy realy extra long message truly really long'
select SUM(200 -Len(tmessage)) AS WASTED,AVG(200 -Len(tmessage)) AS 'Average Wasted',
MIN(200 -Len(tmessage)) AS 'Minimum Wasted'
FROM #T
DROP TABLE #T
WASTEDAverage WastedMinimum Wasted
. . 712 . . . . . 178 . . . . . . .144
But if you are considering altering the size of columns in a existing table, the above could be more useful.
November 20, 2009 at 6:25 pm
As a bit of a side bar... take a look at the WITH ROLLUP and WITH CUBE options on the GROUP BY and the GROUPING function that goes along with it. There's a world of summarized information in those options that are datamart quality without most of the hassle and they blow the COMPUTE clause away. You can use WITH ROLLUP or WITH CUBE in a view and then just select the totals you want, etc, etc, etc.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 20, 2009 at 7:20 pm
wow.. it looks like I have lots of work to do.. if you will excuse me..
:))
excellent tip and I am on my way back to the classroom..
thx
Cheers,
John Esraelo
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply