Viewing 15 posts - 46,456 through 46,470 (of 59,101 total)
vbandlamudi (12/23/2008)
--------------------------------------------------------------------------------
Correct Answer
Select id,name, sal, cumsal=
(select sum(t1.sal)
from employee_san t1
where t1.id <= t.id)
from employee_san t
the above query took 16 seconds to process 27170 rows
and it took 51...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:42 am
I agree... tell us what the rest of the problem is and maybe use the link in my signature to find out how to post some test data. There's...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:27 am
Steve Jones - Editor (12/22/2008)
Indeed, my guess is Jeff if handcrafting something right now in the winter snows of MI.
Heh... just waiting for the specs on the 23 character password/pin....
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:18 am
peter (12/23/2008)
Jeff is quiet about my posts - too quiet....is a storm coming?LOL
Nah... not ignoring you, Peter. Functions do normally contain some unneccessary overhead. Normally... there are exceptions....
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:16 am
I agree... CASE is almost as fast and bit easier to read.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:11 am
r.hensbergen (12/23/2008)
UPDATE #Results
SET @PrevCum_Sal = Cum_Sal = Sal + @PrevCum_Sal,
@PrevName = Name --Just an "anchor"
...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:07 am
Santhosh (12/23/2008)
vbandlamudi (12/23/2008)
Correct Answer
Select id,name, sal, cumsal=
(select sum(t1.sal)
from employee_san t1
where t1.id <= t.id)
from employee_san t
This works fine.
But the salary is not ORDERed BY ASC
It works fine for only...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:04 am
vbandlamudi (12/23/2008)
Correct AnswerSelect id,name, sal, cumsal=
(select sum(t1.sal)
from employee_san t1
where t1.id <= t.id)
from employee_san t
Ummmm... No... that's NOT the correct answer. That makes a triangular join. Try...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 23, 2008 at 5:00 am
Heh... and it works so well for these types of bitwise ops.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 5:18 pm
Ya gotta love it when the ops cooperate.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 5:17 pm
jac (12/22/2008)
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 5:11 pm
Using Luke's good code example, you can label to "sum", as well...
--create test table
CREATE TABLE #test (
id INT,
amount MONEY)
--insert sample data
INSERT INTO [#test]
SELECT 1,10.00
UNION ALL
SELECT 1,20.00
UNION ALL
SELECT 2,10.00
SELECT CASE...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 4:38 pm
That's good advice if you're going to do something like that... but, most maintanence doesn't require a single connection like that. Not sure that's enough justification to give up...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 4:32 pm
kashifyaqoob (12/22/2008)
It is really helpfull for me. Thanks.
Be very careful.... anytime you find the need to update or insert your own numbers into an IDENTITY column, you're probably doing something...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 4:28 pm
Japie Botma (10/21/2005)
--Jeff Moden
Change is inevitable... Change for the better is not.
December 22, 2008 at 4:26 pm
Viewing 15 posts - 46,456 through 46,470 (of 59,101 total)