Using a variable as a column name?

    Date: 12/14/07 (SQL Server)    Keywords: no keywords

    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.

    Source: http://community.livejournal.com/sqlserver/65345.html

« I could use some input on... || checking compatibility level »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home