p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

sql_language thread: SQL- Make column name or Table name a Variable?

Message #1 by Anita Cogar <ACogar@a...> on Wed, 20 Dec 2000 11:47:10 -0500
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')

create procedure YOUR_PROCEDURE_NAME
	@myColumn varchar(25)


declare @mySQL varchar(250)

select @mySQL = 
	'update CMS_TEXT
	SET ' +@myColumn + '= ( SELECT a.' + @MyColumn + 'FROM
_tb_NewCmsText a inner join CMS_TEXT b
							on a.TEXT_ID 
execute (@mySQL)



-----Original Message-----
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
> procedure.  
> 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
> requested.  
> 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

  Return to Index