How to generate a column name in a table dynamically

240 pts.
Tags:
Dynamic SQL
SQL Server 2005
T-SQL
hi, I have to generate dynamic columns for a temp table. I have a temp table with column a, the column b should be generated based on a condition. B conditions are if value> 10 i have to genrate the column as 10 and if the value >20 the column name should be 20 etc....n values.... If i select the table with the condition 20, my output should be a 20 1 x 2 Y 3 Z etc... If i select the table with the condition 100, my output should be b 100 1 x 2 Y 3 Z Can any one help me how to generate this based on T-sql

Answer Wiki

Thanks. We'll let you know when a new response is added.

Dynamic column names are not recommended as they require the use of dynamic SQL which presents security issues when used.

It would be recommended that you have the front end application handle the column renaming based on the values in the recordset.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following