October 11, 2008 at 7:29 am
D'oh! this isn't the first time I've given someone a 2005 solution to a 2000 problem, sorry about that.
October 11, 2008 at 9:41 pm
Alvin Ramard (10/6/2008)
Someone slap me please! All I keep thing about is using a ...... cursor.
Slap... slap, slap... [font="Arial Black"]SLAP![/font]
Heh... Pork chops away!!! 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
October 11, 2008 at 9:42 pm
Chris Harshman (10/11/2008)
D'oh! this isn't the first time I've given someone a 2005 solution to a 2000 problem, sorry about that.
Not your fault... this IS a 2005 forum. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
October 11, 2008 at 10:00 pm
johncyriac (10/11/2008)
...this particular database is in SQL 2000
Heh... [font="Arial Black"]SLAP!!![/font]
Scott's method will absolutely be the fastest. But, just in case you can't do anything to the table or can't create a temp table for some reason, try this...
SELECT hi.St_No, hi.Year, hi.Month, hi.Sal
FROM (SELECT St_No, Year, Month, Sal, DATEADD(mm,Month,DATEADD(yy,Year-1900,0)) AS Date
FROM #t) lo
INNER JOIN
(SELECT St_No, Year, Month, Sal, DATEADD(mm,-1,DATEADD(mm,Month,DATEADD(yy,Year-1900,0))) AS Date
FROM #t) hi
ON (lo.Date = hi.Date
AND lo.St_No = hi.St_No
AND lo.Sal <> hi.Sal)
--Jeff Moden
Change is inevitable... Change for the better is not.
October 13, 2008 at 4:15 am
Hi friends
Thank you all,for the time you spend over this query ,
these type queries are so common in reporting as well as spread sheet ,but no so common in SQL Programming , (Sum if there is a change ,Suppress if duplicated , ... )
Here its the time time to summarize
We can address this problem using
1. CTE
2. Sum /Tally Table Method
3. A select statement which refers to a sub table (select statement ) ,to compare the value with previous recrod
regards
john
October 28, 2008 at 12:55 pm
Heh... Pork chops away!!!
And don't even bother to use a latex-free launcher.
February 8, 2010 at 4:03 pm
Just a note on this. I ran both Scott's and Jeff's solutions; Scott's returned 7 rows and Jeff's returned 5.
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply