Stored procedure (incrementing columns)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
erupt
Forum Commoner
Posts: 58
Joined: Sat Feb 25, 2006 10:24 am

Stored procedure (incrementing columns)

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why not create a variable within the proc and increment it, like you said?
erupt
Forum Commoner
Posts: 58
Joined: Sat Feb 25, 2006 10:24 am

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

var = var + 1;
Post Reply