Image

Imagexterminal wrote in Imagesqlserver

Listens: Loss, "The Turning"

Using a variable as a column name?

I'm trying to write something in a stored procedure (I say "something" because I don't care if it's a SELECT statement, a CREATE TABLE statement, whatever) that will allow me to dynamically declare column names. I've got variables set to 52 week ending dates (@m_week1, @m_week2, etc.), and I need to turn them into 104 column names by adding suffixes ([week1]_dollars, [week1]_units, [week2]_dollars, etc.). Doesn't seem to matter how I do this, however, I get a syntax error.

Can it be done? If so, how?

Thanks.