Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables to define a column name inside a stored procedure

Status
Not open for further replies.

againstTheWind

Programmer
Jun 22, 2006
42
US
I am trying to use variables declared inside my stored procedure to also make-up part of the column name.

Something like this perhaps:

Code:
ALTER PROCEDURE [dbo].[Cust_Recency] @RecentMonth tinyint, @Lastmonth tinyint 
AS

select count(customerid) as [COLOR=red yellow]RecencyFrom@RecentMonthTo@Last[/color] month from
Customers

I am not sure how concatenate the column alias and the variables.

Thanks!
 
The only way to do this would involve dynamic SQL. In my opinion, it's not worth it for this. When displaying the data to the user (in the front end), you could easily change the column name.

Do a little research on dynamic sql. If you still want to do things this way... post back and I'll show you how.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top