Page 1 of 1

Stored procedure (incrementing columns)

Posted: Tue Sep 19, 2006 9:02 am
by erupt
I need to write a stored procedure using this query:

{
select col016, count(distinct contactid)
from sublist_732 s with(nolock) join mydatabase.dbo.mytable e with(nolock)
on s.contactid = e.col014
group by col016
order by col016
}

except instead of just getting a count for column16, (which is col016), i'll need to get it for all columns up to column 251 (which would be col251). So i'll need some sort of way to increment it using a variable so i can return a count for all columns from col016 to col251.. and i'm not sure how to do that.

If there's any confusion in my post, reply back with questions.

Posted: Tue Sep 19, 2006 10:51 am
by RobertGonzalez
Why not create a variable within the proc and increment it, like you said?

Posted: Tue Sep 19, 2006 10:58 am
by erupt
I'm not sure of how to increment ... i have the logic down, :) but i'm unsure of the syntax. :? Do you know the codes to increment what i want to do?

Posted: Tue Sep 19, 2006 11:22 am
by RobertGonzalez

Code: Select all

var = var + 1;