I had this procedure for a while - you can adjust for your needs:
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'YOUR_PROCEDURE_NAME' AND type = 'P')
DROP PROCEDURE YOUR_PROCEDURE_NAME
create procedure YOUR_PROCEDURE_NAME
declare @mySQL varchar(250)
select @mySQL =
SET ' +@myColumn + '= ( SELECT a.' + @MyColumn + 'FROM
_tb_NewCmsText a inner join CMS_TEXT b
--execute YOUR_PROCEDURE_NAME 'COL_NAME'
From: Anita Cogar [mailto:ACogar@a...]
Sent: Wednesday, December 20, 2000 11:47 AM
To: sql language
Subject: [sql_language] SQL- Make column name or Table name a Variable?
> Is possible to make a table name or a column name a variable in a stored
> I have a table that houses a salesperson, his hierarchy and his sales.
> Depending on the level that is passed in (salesperson, supervisor I,
> supervisor II etc..) I want to be able to sum the sales based on the level
> I am currently using "IF logic" but it is cumbersome. I have the exact
> same query in each "IF statement" with minor differences in columns used.
> Any Suggestions?
You are currently subscribed to sql_language as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-sql_language-$subst('Recip.MemberIDChar')@p2p.wrox.com