Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Looping through a table

Author  Topic 

korssane
Posting Yak Master

104 Posts

Posted - 2009-09-15 : 10:55:45
Hi ALl ,

is there a way to use a loop statement into a table in order to assign those values or compare them in a select statement.
Basically the issue is :
i am generating a top 5 issues with their count ( issuename, Count) by descending order for a current week and current day.
I want to compare the current Count with the last week one for the same issuenames on the same day.
Week :1,2,3....53
Day : 1,..7.

What i have done till now is to put all the curent issuenames and count into a table ...My idea is to pull the last week issuenames and count where the lastweek issuename equals the table element (i,j)..

Any help please will be appreciated.. i am really stucked..

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-15 : 11:03:21
table structure, sample data and expected result will be helpful


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-09-15 : 11:05:40
thanks Khtan,
but did not catch any thing..more details please if possible..
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-15 : 11:06:54
Yeah, preferably as executable DDL,DML so we don't have to re-type everything to test the solution:

see this for explanation of Khtan's request:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Be One with the Optimizer
TG
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-09-15 : 11:49:38
i am new guys..
my code is below :

Select t1.issue1,t1.issue2,t1.Count, (select t2.issue1,t2.issue2,t2.Count where ( t2.issue1 = t1.issue1 AND t2.issue2 = t1.issue2 AND t1.Week=@WeekBefore and t1.day=@today ),
From table1 t1
Where (t1.Week=@currenweek and t1.day=@today)

basically i want to compare Count of issue 1,2 of this week with the one of the same issue1,2 of the last week.

please help..
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-15 : 13:43:20
quote:
i am new guys..
my code is below :

korssane, your requirments, as stated, are just not clear enough to provide a working solution. We could take some guesses but that usually just wastes everyone's time. The link I posted is specifically for "new" people. It is detailed instructions on what to provide to get a quick and helpful answer.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -