dynamic column name in view

How can I dynamically change the column name based on the data in the column?

I have a dynamic table(called table A) and  column(column1) in the source table and the data can be dynamically populated ..
For example,

TableA

Column1

Country

Country

----etc…

 And I am trying to create a view that populate column 1 from table A but i need to change the column name based on the value in column1
so the view should return country as columnname

how can i do this inside view?
jung1975Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
>>so the view should return country as columnname

You probably can't do it, just imagine if your view returns more than 1 record ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dqmqCommented:
>You probably can't do it, just imagine if your view returns more than 1 record ?

Or imagine if your view only returns 1 record.  Then the column name and the column value are the same.  What is the  point?
0
_agx_Commented:
I'm not sure I understand the point either. Are you trying to do a PIVOT perhaps..?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jung1975Author Commented:
yes.. Then the column name and the column value should be  the same.. can I do thsi in view?
0
jung1975Author Commented:
the dynamic coulmn will allways have one value.... and the column name should be the same as the value .. hope this make sense?

 
Id           column1
1001      country
1002      country
1908      contry

so the view should return in this case..
Id           COUNTRY
1001      country
1002      country
1908      contry


it can be
Id          region
1001      region
1002      region
1908      region

0
Ryan ChongCommented:
I don't found any problem if we use a generic column name for your dynamic values...

If a dynamic column name is a MUST, a View cannot achieve what you trying to do, perhaps you can try use a Stored Procedure to do it, in your SP, simply generate a dynamic SQL statement based on your requirement, and then EXEC it.
0
dqmqCommented:
Agreed, not possible in a view.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.